Liking cljdoc? Tell your friends :D

ham-fisted.lazy-noncaching

Lazy, noncaching implementation of many clojure.core functions. There are several benefits of carefully constructed lazy noncaching versions:

  1. No locking - better multithreading/green thread performance.
  2. Higher performance generally.
  3. More datatype flexibility - if map is passed a single randomly addressible or generically parallelizable container the result is still randomly addressible or generically perallelizable. For instance (map key {:a 1 :b 2}) returns in the generic case something that can still be parallelizable as the entry set of a map implements spliterator.
Lazy, noncaching implementation of many clojure.core functions.  There are several benefits of carefully
constructed lazy noncaching versions:

1. No locking - better multithreading/green thread performance.
2. Higher performance generally.
3. More datatype flexibility - if map is passed a single randomly addressible or generically
parallelizable container the result is still randomly addressible or generically perallelizable.
For instance (map key {:a 1 :b 2}) returns in the generic case something that can still be parallelizable
as the entry set of a map implements spliterator.
raw docstring

->collectionclj

(->collection item)

Ensure an item implements java.util.Collection. This is inherently true for seqs and any implementation of java.util.List but not true for object arrays. For maps this returns the entry set.

Ensure an item implements java.util.Collection.  This is inherently true for seqs and any
implementation of java.util.List but not true for object arrays.  For maps this returns
the entry set.
raw docstring

->iterableclj

(->iterable a)

->random-accessclj

(->random-access item)

->reducibleclj

(->reducible item)

apply-concatclj

(apply-concat)
(apply-concat data)

as-random-accessclj

(as-random-access item)

If item implements RandomAccess, return List interface.

If item implements RandomAccess, return List interface.
raw docstring

cartesian-mapclj

(cartesian-map f)
(cartesian-map f a)
(cartesian-map f a b)
(cartesian-map f a b & args)

Create a new sequence that is the cartesian join of the input sequence passed through f. Unlike map, f is passed the arguments as a single persistent vector. This is to enable much higher efficiency in the higher-arity applications. For tight numeric loops, see ham-fisted.hlet/let.

The argument vector is mutably updated between function calls so you can't cache it. Use (into [] args) or some variation thereof to cache the arguments as is.

user> (hamf/sum-fast (lznc/cartesian-map
                      #(h/let [[a b c d](lng-fns %)]
                         (-> (+ a b) (+ c) (+ d)))
                      [1 2 3]
                      [4 5 6]
                      [7 8 9]
                      [10 11 12 13 14]))
3645.0
Create a new sequence that is the cartesian join of the input sequence passed through f.
  Unlike map, f is passed the arguments as a single persistent vector.  This is to enable much
  higher efficiency in the higher-arity applications.  For tight numeric loops, see [[ham-fisted.hlet/let]].

  The argument vector is mutably updated between function calls so you can't cache it.  Use `(into [] args)`
  or some variation thereof to cache the arguments as is.

```clojure
user> (hamf/sum-fast (lznc/cartesian-map
                      #(h/let [[a b c d](lng-fns %)]
                         (-> (+ a b) (+ c) (+ d)))
                      [1 2 3]
                      [4 5 6]
                      [7 8 9]
                      [10 11 12 13 14]))
3645.0
```
raw docstring

concatclj

(concat)
(concat a)
(concat a & args)

constant-countclj

(constant-count data)

Constant time count. Returns nil if input doesn't have a constant time count.

Constant time count.  Returns nil if input doesn't have a constant time count.
raw docstring

constant-countable?clj

(constant-countable? data)

empty-vecclj


every?clj

(every? pred coll)

Faster (in most circumstances) implementation of clojure.core/every?. This can be much faster in the case of primitive arrays of values. Type-hinted functions are best if coll is primitive array - see example.

user> (type data)
[J
user> (count data)
100
user> (def vdata (vec data))
#'user/vdata
user> (crit/quick-bench (every? (fn [^long v] (> v 80)) data))
             Execution time mean : 40.248868 ns
nil
user> (crit/quick-bench (lznc/every? (fn [^long v] (> v 80)) data))
             Execution time mean : 7.601190 ns
nil
user> (crit/quick-bench (every? (fn [^long v] (< v 80)) vdata))
             Execution time mean : 1.269582 µs
nil
user> (crit/quick-bench (lznc/every? (fn [^long v] (< v 80)) vdata))
             Execution time mean : 211.645613 ns
nil
user>
Faster (in most circumstances) implementation of clojure.core/every?.  This can be much faster in the case
  of primitive arrays of values.  Type-hinted functions are best if coll is primitive array - see example.

```clojure
user> (type data)
[J
user> (count data)
100
user> (def vdata (vec data))
#'user/vdata
user> (crit/quick-bench (every? (fn [^long v] (> v 80)) data))
             Execution time mean : 40.248868 ns
nil
user> (crit/quick-bench (lznc/every? (fn [^long v] (> v 80)) data))
             Execution time mean : 7.601190 ns
nil
user> (crit/quick-bench (every? (fn [^long v] (< v 80)) vdata))
             Execution time mean : 1.269582 µs
nil
user> (crit/quick-bench (lznc/every? (fn [^long v] (< v 80)) vdata))
             Execution time mean : 211.645613 ns
nil
user>
```
raw docstring

filterclj

(filter pred)
(filter pred coll)

into-arrayclj

(into-array aseq)
(into-array ary-type aseq)
(into-array ary-type mapfn aseq)

make-readonly-listcljmacro

(make-readonly-list n idxvar read-code)
(make-readonly-list cls-type-kwd n idxvar read-code)

Implement a readonly list. If cls-type-kwd is provided it must be, at compile time, either :int64, :float64 or :object and the getLong, getDouble or get interface methods will be filled in, respectively. In those cases read-code must return the appropriate type.

Implement a readonly list.  If cls-type-kwd is provided it must be, at compile time,
either :int64, :float64 or :object and the getLong, getDouble or get interface methods
will be filled in, respectively.  In those cases read-code must return the appropriate
type.
raw docstring

mapclj

(map f)
(map f arg)
(map f arg & args)

map-indexedclj

(map-indexed map-fn coll)

map-reducibleclj

(map-reducible f r)

Map a function over r - r need only be reducible. Returned value does not implement seq but is countable when r is countable.

Map a function over r - r need only be reducible.  Returned value does not implement
seq but is countable when r is countable.
raw docstring

object-arrayclj

(object-array item)

Faster version of object-array for eductions, java collections and strings.

Faster version of object-array for eductions, java collections and strings.
raw docstring

partition-allclj

(partition-all n)
(partition-all n coll)
(partition-all n step coll)

Lazy noncaching version of partition-all. When input is random access returns random access result.

If input is not random access then similar to partition-by each sub-collection must be entirely iterated through before requesting the next sub-collection.

user> (crit/quick-bench (mapv hamf/sum-fast (lznc/partition-all 100 (range 100000))))
             Execution time mean : 335.821098 µs
nil
user> (crit/quick-bench (mapv hamf/sum-fast (partition-all 100 (range 100000))))
             Execution time mean : 6.831242 ms
nil
user> (crit/quick-bench (into [] (comp (partition-all 100)
                                       (map hamf/sum-fast))
                              (range 100000)))
             Execution time mean : 1.645954 ms
nil
Lazy noncaching version of partition-all.  When input is random access returns random access result.

  If input is not random access then similar to [[partition-by]] each sub-collection must be entirely
  iterated through before requesting the next sub-collection.

```clojure
user> (crit/quick-bench (mapv hamf/sum-fast (lznc/partition-all 100 (range 100000))))
             Execution time mean : 335.821098 µs
nil
user> (crit/quick-bench (mapv hamf/sum-fast (partition-all 100 (range 100000))))
             Execution time mean : 6.831242 ms
nil
user> (crit/quick-bench (into [] (comp (partition-all 100)
                                       (map hamf/sum-fast))
                              (range 100000)))
             Execution time mean : 1.645954 ms
nil
```
raw docstring

partition-byclj

(partition-by f)
(partition-by f coll)
(partition-by f options coll)

Lazy noncaching version of partition-by. For reducing partitions into a singular value please see apply-concat. Return value most efficiently implements reduce with a slightly less efficient implementation of Iterable.

Unlike clojure.core/partition-by this does not store intermediate elements nor does it build up intermediate containers. This makes it somewhat faster in most contexts.

Each sub-collection must be iterated through entirely before the next method of the parent iterator else the result will not be correct.

Options:

  • :ignore-leftover? - When true leftover items in the previous iteration do not cause an exception. Defaults to false.
  • :binary-predicate - When provided, use this for equality semantics. Defaults to equiv semantics but in a numeric context it may be useful to have '(== ##NaN ##Nan).
user> ;;incorrect - inner items not iterated and non-caching!
user> (into [] (lznc/partition-by identity [1 1 1 2 2 2 3 3 3]))
Execution error at ham_fisted.lazy_noncaching.PartitionBy/reduce (lazy_noncaching.clj:514).
Sub-collection was not entirely consumed.

user> ;;correct - transducing form of into calls vec on each sub-collection
user> ;;thus iterating through it entirely.
user> (into [] (map vec) (lznc/partition-by identity [1 1 1 2 2 2 3 3 3]))
[[1 1 1] [2 2 2] [3 3 3]]
user> ;;filter,collect NaN out of sequence
user> (lznc/map hamf/vec (lznc/partition-by identity {:binary-predicate (hamf-fn/binary-predicate
                                                                         x y (let [x (double x)
                                                                                   y (double y)]
                                                                               (cond
                                                                                 (Double/isNaN x)
                                                                                 (if (Double/isNaN y)
                                                                                   true
                                                                                   false)
                                                                                 (Double/isNaN y) false
                                                                                 :else true))) }
                                            [1 2 3 ##NaN ##NaN 3 4 5]))
([1 2 3] [NaN NaN] [3 4 5])

user> (def init-data (vec (lznc/apply-concat (lznc/map #(repeat 100 %) (range 1000)))))
#'user/init-data
user> (crit/quick-bench (mapv hamf/sum-fast (lznc/partition-by identity init-data)))
             Execution time mean : 366.915796 µs
  ...
nil
user> (crit/quick-bench (mapv hamf/sum-fast (clojure.core/partition-by identity init-data)))
             Execution time mean : 6.699424 ms
  ...
nil
user> (crit/quick-bench (into [] (comp (clojure.core/partition-by identity)
                                       (map hamf/sum-fast)) init-data))
             Execution time mean : 1.705864 ms
  ...
Lazy noncaching version of partition-by.  For reducing partitions into a singular value please see
  [[apply-concat]].  Return value most efficiently implements reduce with a slightly less efficient
  implementation of Iterable.

  Unlike clojure.core/partition-by this does not store intermediate elements nor does it build
  up intermediate containers.  This makes it somewhat faster in most contexts.

  Each sub-collection must be iterated through entirely before the next method of the parent iterator
  else the result will not be correct.

  Options:

  * `:ignore-leftover?` - When true leftover items in the previous iteration do not cause an exception.
  Defaults to false.
  * `:binary-predicate` - When provided, use this for equality semantics.  Defaults to equiv semantics
     but in a numeric context it may be useful to have '(== ##NaN ##Nan).


```clojure
user> ;;incorrect - inner items not iterated and non-caching!
user> (into [] (lznc/partition-by identity [1 1 1 2 2 2 3 3 3]))
Execution error at ham_fisted.lazy_noncaching.PartitionBy/reduce (lazy_noncaching.clj:514).
Sub-collection was not entirely consumed.

user> ;;correct - transducing form of into calls vec on each sub-collection
user> ;;thus iterating through it entirely.
user> (into [] (map vec) (lznc/partition-by identity [1 1 1 2 2 2 3 3 3]))
[[1 1 1] [2 2 2] [3 3 3]]
user> ;;filter,collect NaN out of sequence
user> (lznc/map hamf/vec (lznc/partition-by identity {:binary-predicate (hamf-fn/binary-predicate
                                                                         x y (let [x (double x)
                                                                                   y (double y)]
                                                                               (cond
                                                                                 (Double/isNaN x)
                                                                                 (if (Double/isNaN y)
                                                                                   true
                                                                                   false)
                                                                                 (Double/isNaN y) false
                                                                                 :else true))) }
                                            [1 2 3 ##NaN ##NaN 3 4 5]))
([1 2 3] [NaN NaN] [3 4 5])

user> (def init-data (vec (lznc/apply-concat (lznc/map #(repeat 100 %) (range 1000)))))
#'user/init-data
user> (crit/quick-bench (mapv hamf/sum-fast (lznc/partition-by identity init-data)))
             Execution time mean : 366.915796 µs
  ...
nil
user> (crit/quick-bench (mapv hamf/sum-fast (clojure.core/partition-by identity init-data)))
             Execution time mean : 6.699424 ms
  ...
nil
user> (crit/quick-bench (into [] (comp (clojure.core/partition-by identity)
                                       (map hamf/sum-fast)) init-data))
             Execution time mean : 1.705864 ms
  ...
```
raw docstring

reindexclj

(reindex coll indexes)

Permut coll by the given indexes. Result is random-access and the same length as the index collection. Indexes are expected to be in the range of [0->count(coll)).

Permut coll by the given indexes.  Result is random-access and the same length as
the index collection.  Indexes are expected to be in the range of [0->count(coll)).
raw docstring

removeclj

(remove pred)
(remove pred coll)

Returns a lazy sequence of the items in coll for which (pred item) returns logical false. pred must be free of side-effects. Returns a transducer when no collection is provided.

Returns a lazy sequence of the items in coll for which
(pred item) returns logical false. pred must be free of side-effects.
Returns a transducer when no collection is provided.
raw docstring

repeatedlyclj

(repeatedly f)
(repeatedly n f)

When called with one argument, produce infinite list of calls to v. When called with two arguments, produce a non-caching random access list of length n of calls to v.

When called with one argument, produce infinite list of calls to v.
When called with two arguments, produce a non-caching random access list of length n of calls to v.
raw docstring

seed->randomclj

(seed->random seed)

shiftclj

(shift n coll)

Shift a collection forward or backward repeating either the first or the last entries. Returns a random access list with the same elements as coll.

Example:

ham-fisted.api> (shift 2 (range 10))
[0 0 0 1 2 3 4 5 6 7]
ham-fisted.api> (shift -2 (range 10))
[2 3 4 5 6 7 8 9 9 9]
Shift a collection forward or backward repeating either the first or the last entries.
  Returns a random access list with the same elements as coll.

  Example:

```clojure
ham-fisted.api> (shift 2 (range 10))
[0 0 0 1 2 3 4 5 6 7]
ham-fisted.api> (shift -2 (range 10))
[2 3 4 5 6 7 8 9 9 9]
```
raw docstring

shuffleclj

(shuffle coll)
(shuffle coll opts)

shuffle values returning random access container.

Options:

  • :seed - If instance of java.util.Random, use this. If integer, use as seed. If not provided a new instance of java.util.Random is created.
shuffle values returning random access container.

Options:

* `:seed` - If instance of java.util.Random, use this.  If integer, use as seed.
If not provided a new instance of java.util.Random is created.
raw docstring

tuple-mapclj

(tuple-map f c1)
(tuple-map f c1 c2)
(tuple-map f c1 c2 & cs)

Lazy nonaching map but f simply gets a single random-access list of arguments. The argument list may be mutably updated between calls.

Lazy nonaching map but f simply gets a single random-access list of arguments.
The argument list may be mutably updated between calls.
raw docstring

type-single-arg-ifnclj

(type-single-arg-ifn ifn)

Categorize the return type of a single argument ifn. May be :float64, :int64, or :object.

Categorize the return type of a single argument ifn.  May be :float64, :int64, or :object.
raw docstring

type-zero-arg-ifnclj

(type-zero-arg-ifn ifn)

Categorize the return type of a single argument ifn. May be :float64, :int64, or :object.

Categorize the return type of a single argument ifn.  May be :float64, :int64, or :object.
raw docstring

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

× close