Public Vars

Back

juxt (clj)

(source)

function

(juxt f) (juxt f g) (juxt f g h) (juxt f g h & fs)
Takes a set of functions and returns a fn that is the juxtaposition of those fns. The returned fn takes a variable number of args, and returns a vector containing the result of applying each fn to the args (left-to-right). ((juxt a b c) x) => [(a x) (b x) (c x)]

Examples

clojure
(ns clojure.test-clojure.reducers
  (:require [clojure.core.reducers :as r]
            [clojure.test.generative :refer (defspec)]
            [clojure.data.generators :as gen])
  (:use clojure.test))

(deftest test-mapcat-obeys-reduced
  (is (= [1 "0" 2 "1" 3]
        (->> (concat (range 100) (lazy-seq (throw (Exception. "Too eager"))))
          (r/mapcat (juxt inc str))
          (r/take 5)
          (into [])))))
clojure/core.typed
(ns clojure.core.typed.analyzer.jvm-test
  (:require [clojure.test :refer :all]
            [clojure.core.typed.analyzer.jvm.passes.emit-form :refer [emit-form]]
            [clojure.core.typed.analyzer.jvm :as ana]))

(deftest analyzer-test
  (is (= 1
         (:result (ast 1))))
  (is (= 2 
         (:result (ast (-> 1 inc)))))
  (is (= 1
         (:result (ast (let [a 1] a)))))
  (is (= 1
         (:result (ast (loop [a 1] a)))))
  (is (= 1
         (:result (ast (do (def a 1)
                           a)))))
  (is (= 1
         (:result (ast (do (deftype Abc [a])
                           (.a (->Abc 1)))))))
  (is (= true
         (:result (ast (do (ns foo) (= 1 1))))))
  (is (= "a"
         (:result (ast (.toString (reify Object (toString [this] "a")))))))
  (is (= 2 (:result (ast (#(inc %) 1)))))
  #_
  (is (->
        (ast (do (ns bar
                   (:require [clojure.core.typed :as t]))
                 (t/ann-form 'foo 'a)))
        :ret))
  (is (= [:const Number]
         ((juxt :op :val) (ast Number))))
  (is (= [:const clojure.lang.Compiler]
         ((juxt :op :val) (ast clojure.lang.Compiler))))
  (is (= [:static-field 'LOADER]
         ((juxt :op :field) (ast clojure.lang.Compiler/LOADER))))
  )

(deftest local-tag-test
  (is (= java.lang.String
         (:tag (ast "asdf"))))
  (is (= [:const java.lang.String]
         (-> (ast (let [a "asdf"]))
             :bindings
             first
             :init
             ((juxt :op :tag)))))
  (is (= [:binding java.lang.String]
         (-> (ast (let [a "asdf"]))
             :bindings
             first
             ((juxt :op :tag)))))
  (is (= [:local java.lang.String]
         (-> (ast (let [a "asdf"]
                    a))
             :body
             :ret
             ((juxt :op :tag)))))
  (is (= java.lang.String
         (:tag (ast (let [a "asdf"]
                      a)))))
  )
clojure/core.typed
(ns clojure.core.typed.test.file-mapping
  (:require 
    ; this loads the type system, must go first
    [clojure.core.typed.test.test-utils :refer [check clj]]
    [clojure.core.typed.checker.jvm.analyze-clj :as ana]
    [clojure.core.typed :as t]
    [clojure.core.typed.checker.jvm.check :as chk]))

#_(-> (ana/ast-for-form '(let [a (+ 1 2)] a)) :env ((juxt :line :column)))

#_(-> (ana/ast-for-form '(let [{:as a} {}] a)) :env ((juxt :line :column)))
originrose/cortex
(ns cortex.optimise.optimisers-test
  (:refer-clojure :exclude [+ - * /])
  (:require [clojure.core.matrix.operators :refer [+ - * /]]
            [clojure.test :refer :all]
            [cortex.optimise.optimisers :refer :all]
            [cortex.optimise.protocols :as cp]
            [cortex.util :refer [approx= def-]]))

(deftest protocol-extension-test
  (testing "map as optimiser"
    (is (= (->> test-optimiser-map
             (iterate #(cp/compute-parameters % [1 2 3] (or (cp/parameters %)
                                                            [0 0 0])))
             (map (juxt cp/parameters cp/get-state))
             (rest)
             (take 3))
           [[[0 0 0] {:velocity [1 2 3]}]
            [[1 2 3] {:velocity [2 4 6]}]
            [[3 6 9] {:velocity [3 6 9]}]])))
  (testing "fn as optimiser"
    (is (= (->> test-optimiser-fn
             (iterate #(cp/compute-parameters % [1 2 3] (or (cp/parameters %)
                                                            [0 0 0])))
             (map (juxt cp/parameters cp/get-state))
             (rest)
             (take 3))
           [[[1 2 3] {}]
            [[2 4 6] {}]
            [[3 6 9] {}]]))))

(deftest sgd-clojure-test
  (is (= (-> (sgd-clojure :learning-rate 5)
           (cp/compute-parameters [2 4 8] [1 2 3])
           ((juxt cp/parameters cp/get-state)))
         [[-9 -18 -37] {}])))

(deftest adadelta-clojure-test
  (is (approx= 1e-8
               (-> (adadelta-clojure :decay-rate 0.5
                                     :conditioning 1)
                 (assoc-in [:state :acc-gradient] [6 3 9])
                 (assoc-in [:state :acc-step] [7 8 7])
                 (dissoc :initialize)
                 (cp/compute-parameters [2 4 8] [1 2 3])
                 ((juxt cp/parameters cp/get-state)))
               ;; The following was computed manually using a calculator.
               [[-1.309401077 -1.703280399 -0.6950417228]
                {:acc-gradient [5.0 9.5 36.5]
                 :acc-step [6.166666667 10.85714286 10.32666667]}])))

(deftest adam-clojure-test
  (is (approx= 1e-8
               (-> (adam-clojure :step-size 5
                                 :first-moment-decay 0.75
                                 :second-moment-decay 0.3
                                 :conditioning 0.2)
                 (assoc-in [:state :first-moment] [5 2 -3])
                 (assoc-in [:state :second-moment] [-1 -3 -8])
                 (assoc-in [:state :num-steps] 2)
                 (dissoc :initialize)
                 (cp/compute-parameters [5 3 7] [1 2 -5])
                 ((juxt cp/parameters cp/get-state)))
               ;; The following was computed manually using a calculator.
               [[-8.81811015 -5.613809809 -4.270259223]
                {:first-moment [5.0 2.25 -0.5]
                 :second-moment [17.2 5.4 31.9]
                 :num-steps 3}])))
typedclojure/typedclojure
(ns ^:no-doc typed.ann.clojure
  "Type annotations for the base Clojure distribution."
  #?(:cljs (:require-macros [typed.ann-macros.clojure :as macros]))
  (:require [clojure.core :as cc]
            [typed.clojure :as t]
            #?(:clj [typed.ann-macros.clojure :as macros])
            #?(:clj typed.ann.clojure.jvm) ;; jvm annotations
            #?(:clj clojure.core.typed))
  #?(:clj
     (:import (clojure.lang PersistentHashSet PersistentList
                            APersistentMap #_IPersistentCollection
                            #_ITransientSet
                            IRef)
              (java.util Comparator Collection))))

;cc/juxt
;(t/All [b1 :..]
;(t/All [x r b2 :..]
;     (Fn [[b1 :.. b1 :-> b2] :.. b2 :-> [b1 :.. b1 :-> '[b2 :.. b2]]]
;         [[b1 :.. b1 :-> r] :* :-> [b1 :.. b1 :-> (t/Vec r)]]
;         [[x :* :-> b2] :.. b2 :-> [x :* :-> '[b2 :.. b2]]]
;         [[x :* :-> r] :* :-> [x :* :-> (t/Vec r)]])))
ReactiveX/RxClojure
(ns rx.lang.clojure.graph-test
  (:require [rx.lang.clojure.graph :as graph]
            [rx.lang.clojure.core :as rx]
            [rx.lang.clojure.future :as rx-future]
            [rx.lang.clojure.blocking :as rx-blocking]
            [clojure.test :refer [deftest testing is]]))

                        ?ab-lookup (->> ?ab
                                        (rx/map (juxt :user-id #(dissoc % :user-id)))
                                        (rx/into {}))