Liking cljdoc? Tell your friends :D

flatland.useful.fn


!clj

source

=toclj

(=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.
sourceraw docstring

allclj

(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.
sourceraw docstring

annotateclj

(annotate x & fs)

A vector of [x (f1 x) (f2 x) ...].

A vector of [x (f1 x) (f2 x) ...].
sourceraw docstring

anyclj

(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.
sourceraw docstring

apclj

A shorthand version of applied

A shorthand version of applied
sourceraw docstring

appliedclj

(applied f)

A version of f that uses apply on its args.

A version of f that uses apply on its args.
sourceraw docstring

as-fnclj

(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.
sourceraw docstring

decorateclj

(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) ...].
sourceraw docstring

fixclj

(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.
sourceraw docstring

fixingclj

(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)
sourceraw docstring

givencljmacro

(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)))
sourceraw docstring

ignoring-nilsclj

(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.
sourceraw docstring

key-comparatorclj

(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).
sourceraw docstring

knitclj

(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 &&&).
sourceraw docstring

memoize-lastclj

(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.
sourceraw docstring

rate-limitedclj

(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.
sourceraw docstring

thrushclj

(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
sourceraw docstring

to-fixclj

(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.
sourceraw docstring

validatorclj

(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.
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close