Public Vars

Back

partial (clj)

(source)

function

(partial f) (partial f arg1) (partial f arg1 arg2) (partial f arg1 arg2 arg3) (partial f arg1 arg2 arg3 & more)
Takes a function f and fewer than the normal arguments to f, and returns a fn that takes a variable number of additional args. When called, the returned function calls f with args + additional args.

Examples

clojure
(deftest division
  (is (= clojure.core// /))
  (binding [*ns* *ns*]
    (eval '(do (ns foo
                 (:require [clojure.core :as bar])
                 (:use [clojure.test]))
               (is (= clojure.core// bar//))))))

(deftest unknown-tag
  (let [my-unknown (fn [tag val] {:unknown-tag tag :value val})
        throw-on-unknown (fn [tag val] (throw (RuntimeException. (str "No data reader function for tag " tag))))
        my-uuid (partial my-unknown 'uuid)
        u "#uuid \"550e8400-e29b-41d4-a716-446655440000\""
        s "#never.heard.of/some-tag [1 2]" ]
    (binding [*data-readers* {'uuid my-uuid}
              *default-data-reader-fn* my-unknown]
      (testing "Unknown tag"
        (is (= (read-string s)
               {:unknown-tag 'never.heard.of/some-tag
                :value [1 2]})))
      (testing "Override uuid tag"
        (is (= (read-string u)
               {:unknown-tag 'uuid
                :value "550e8400-e29b-41d4-a716-446655440000"}))))
hoplon/hoplon
(ns hoplon.binding
  (:refer-clojure :exclude [binding bound-fn])
  (:require [clojure.core  :as clj]
            [cljs.analyzer :as a]))

(defmacro binding
  "See clojure.core/binding."
  [bindings & body]
  (let [env           (assoc &env :ns (a/get-namespace a/*cljs-ns*))
        value-exprs   (take-nth 2 (rest bindings))
        bind-syms     (map #(:name (a/resolve-existing-var env %)) (take-nth 2 bindings))
        bind-syms'    (map (partial list 'quote) bind-syms)
        set-syms      (repeatedly (count bind-syms) gensym)
        setfn         (fn [x y]
                        {:push! `(fn []
                                   (let [z# ~x]
                                     (set! ~x ~y)
                                     (fn [] (set! ~x z#))))})
        thunkmaps     (map setfn bind-syms set-syms)]
    (a/confirm-bindings env bind-syms)
    `(let [~@(interleave set-syms value-exprs)]
       (hoplon.binding/push-thread-bindings ~(zipmap bind-syms' thunkmaps))
       (try ~@body (finally (hoplon.binding/pop-thread-bindings))))))
hraberg/deuce
(ns deuce.emacs.callproc
  (:use [deuce.emacs-lisp :only (defun defvar) :as el])
  (:require [clojure.core :as c]
            [clojure.string :as s]
            [clojure.java.io :as io]
            [clojure.java.shell :as sh]
            [deuce.emacs.buffer :as buffer]
            [deuce.emacs.data :as data]
            [deuce.emacs.editfns :as editfns])
  (:import [java.io File])
  (:refer-clojure :exclude []))

(defvar process-environment (apply list (map (partial s/join "=") (into {} (System/getenv))))
  "List of overridden environment variables for subprocesses to inherit.
  Each element should be a string of the form ENVVARNAME=VALUE.
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))))

;partial: wishful thinking (replaces the first 4 arities)
; (t/All [r b1 :.. b2 :..]
;    [[b1 :.. b1 b2 :.. b2 :-> r] b1 :.. b1 :-> [b2 :.. b2 :-> r]])

cc/partial
(t/All [y a b c d z :..]
       (t/IFn [[z :.. z :-> y] :-> [z :.. z :-> y]]
              [[a z :.. z :-> y] a :-> [z :.. z :-> y]]
              [[a b z :.. z :-> y] a b :-> [z :.. z :-> y]]
              [[a b c z :.. z :-> y] a b c :-> [z :.. z :-> y]]
              [[a b c d z :.. z :-> y] a b c d :-> [z :.. z :-> y]]
              [[a :* :-> y] a :* :-> [a :* :-> y]]))
FundingCircle/jackdaw
(ns jackdaw.serdes.avro.integration-test
  (:require [clj-uuid :as uuid]
            [clojure.core.cache :as cache]
            [clojure.java.io :as io]
            [clojure.test :refer [deftest is testing]]
            [jackdaw.client :as jc]
            [jackdaw.client.log :as jcl]
            [jackdaw.data :as jd]
            [jackdaw.serdes.avro :as avro]
            [jackdaw.serdes.avro.schema-registry :as reg]
            [jackdaw.test.fixtures :as fix])
  (:import [org.apache.kafka.common.serialization Serde Serdes]))

(def serde*
  (partial avro/serde +type-registry+ +real-schema-registry+))
gerritjvv/fmap-clojure
(ns fmap-clojure.applicative-tests
  (:require [fmap-clojure.core :refer [<*> >>=*]])
  (:use midje.sweet))

(facts "Test <*>"
       
       (fact "Test <*> over single argument"
             (<*> [inc] [1]) => [2])
       (fact "Test <*> over 4 arguments"
             (<*> [inc] [1 2 3 4]) => [2 3 4 5])
       (fact "Test <*> over 1 int and a nested list of 4 arguments"
             (<*> [inc] [1 [1 2 3 4]]) => [2 [2 3 4 5]])
       (fact "Test fmap for maps"
             (prn 
               (>>=* [{:topic "a" :partition 1 :val "hi"} 
                      {:topic "b" :partition 2 :val "hi2"}]
                      (partial group-by :topic))
               ))
                   
       )