(=to x)
Produces an equality predicate from a single object. ((=to x) y) is the same as (= x y), but if the returned function will be called many times it may be more efficient than repeated calls to =, because =to can short-circuit many irrelevant code paths based on knowing the type of x.
Just a wrapper for clojure.lang.Util/equivPred.
Produces an equality predicate from a single object. ((=to x) y) is the same as (= x y), but if the returned function will be called many times it may be more efficient than repeated calls to =, because =to can short-circuit many irrelevant code paths based on knowing the type of x. Just a wrapper for clojure.lang.Util/equivPred.
(all & preds)
Takes a list of predicates and returns a new predicate that returns true if all do.
Takes a list of predicates and returns a new predicate that returns true if all do.
(annotate x & fs)
A vector of [x (f1 x) (f2 x) ...].
A vector of [x (f1 x) (f2 x) ...].
(any & preds)
Takes a list of predicates and returns a new predicate that returns true if any do.
Takes a list of predicates and returns a new predicate that returns true if any do.
(applied f)
A version of f that uses apply on its args.
A version of f that uses apply on its args.
(as-fn x)
Turn an object into a fn if it is not already, by wrapping it in constantly.
Turn an object into a fn if it is not already, by wrapping it in constantly.
(decorate & fs)
Return a function f such that (f x) => [x (f1 x) (f2 x) ...].
Return a function f such that (f x) => [x (f1 x) (f2 x) ...].
(fix x & clauses)
Walk through clauses, a series of predicate/transform pairs. The first predicate that x satisfies has its transformation clause called on x. Predicates or transforms may be values (eg true or nil) rather than functions; these will be treated as functions that return that value.
The last "pair" may be only a transform with no pred: in that case it is unconditionally used to transform x, if nothing previously matched.
If no predicate matches, then x is returned unchanged.
Walk through clauses, a series of predicate/transform pairs. The first predicate that x satisfies has its transformation clause called on x. Predicates or transforms may be values (eg true or nil) rather than functions; these will be treated as functions that return that value. The last "pair" may be only a transform with no pred: in that case it is unconditionally used to transform x, if nothing previously matched. If no predicate matches, then x is returned unchanged.
(fixing x pred transform & args)
A version of fix that fits better with the unified update model: instead of multiple clauses, additional args to the transform function are permitted. For example, (swap! my-atom fixing map? update-in [k] inc)
A version of fix that fits better with the unified update model: instead of multiple clauses, additional args to the transform function are permitted. For example, (swap! my-atom fixing map? update-in [k] inc)
(given x & clauses)
A macro combining the features of fix and fixing, by using parentheses to group the additional arguments to each clause: (-> x (given string? read-string map? (dissoc :x :y :z) even? (/ 2)))
A macro combining the features of fix and fixing, by using parentheses to group the additional arguments to each clause: (-> x (given string? read-string map? (dissoc :x :y :z) even? (/ 2)))
(ignoring-nils f)
Create a new version of a function which ignores all nils in its arguments: ((ignoring-nils +) 1 nil 2 3 nil) yields 6.
Create a new version of a function which ignores all nils in its arguments: ((ignoring-nils +) 1 nil 2 3 nil) yields 6.
(key-comparator modifier)
(key-comparator direction modifier)
Given a transformation function (and optionally a direction), return a comparator which does its work by comparing the values of (transform x) and (transform y).
Given a transformation function (and optionally a direction), return a comparator which does its work by comparing the values of (transform x) and (transform y).
(knit & fs)
Takes a list of functions (f1 f2 ... fn) and returns a new function F. F takes a collection of size n (x1 x2 ... xn) and returns a vector [(f1 x1) (f2 x2) ... (fn xn)]. Similar to Haskell's ***, and a nice complement to juxt (which is Haskell's &&&).
Takes a list of functions (f1 f2 ... fn) and returns a new function F. F takes a collection of size n (x1 x2 ... xn) and returns a vector [(f1 x1) (f2 x2) ... (fn xn)]. Similar to Haskell's ***, and a nice complement to juxt (which is Haskell's &&&).
(memoize-last f)
A version of memoize that only remembers the result for a single input argument at a time. eg, if you call (f 1) (f 1) (f 2) (f 1), only the second call is memoized, because it is the same argument you just gave. The third and fourth calls see a new argument, and therefore refresh the cached value.
A version of memoize that only remembers the result for a single input argument at a time. eg, if you call (f 1) (f 1) (f 2) (f 1), only the second call is memoized, because it is the same argument you just gave. The third and fourth calls see a new argument, and therefore refresh the cached value.
(rate-limited f ms-period)
Create a version of a function which 'refuses' to be called too frequently. If it has successfully been called in the last N milliseconds, calls to it will return nil; if no calls have succeeded in that period, args will be passed along to the base function.
Create a version of a function which 'refuses' to be called too frequently. If it has successfully been called in the last N milliseconds, calls to it will return nil; if no calls have succeeded in that period, args will be passed along to the base function.
(thrush & args)
Takes the first argument and applies the remaining arguments to it as functions from left to right. This tiny implementation was written by Chris Houser. http://blog.fogus.me/2010/09/28/thrush-in-clojure-redux
Takes the first argument and applies the remaining arguments to it as functions from left to right. This tiny implementation was written by Chris Houser. http://blog.fogus.me/2010/09/28/thrush-in-clojure-redux
(to-fix & clauses)
A "curried" version of fix, which sets the clauses once, yielding a function that calls fix with the specified first argument.
A "curried" version of fix, which sets the clauses once, yielding a function that calls fix with the specified first argument.
(validator pred)
Create a version of a predicate that only tests its output for truthiness, returning the original input value if the predicate evaluates to anything truthy, and nil otherwise. ((validator even?) 10) => 10, even though (even? 10) is true.
Create a version of a predicate that only tests its output for truthiness, returning the original input value if the predicate evaluates to anything truthy, and nil otherwise. ((validator even?) 10) => 10, even though (even? 10) is true.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close