Liking cljdoc? Tell your friends :D

com.michaelgaare.clj-util.transform

Transformation utility functions.

  • restructure to rewrite maps
  • val-map map functions over map values
Transformation utility functions.
- `restructure` to rewrite maps
- `val-map` map functions over map values
raw docstring

distinct-byclj

(distinct-by f)
(distinct-by f coll)

Like distinct, but calls f on each item to determine the distinct value, while returning the original un-transformed item. Returns a transducer if called without a collection argument.

Like distinct, but calls f on each item to determine the distinct
value, while returning the original un-transformed item. Returns a
transducer if called without a collection argument.
raw docstring

literalclj

(literal x)

For use in restructure, marks a value as one that should be preserved literally in the output.

For use in `restructure`, marks a value as one that should be
preserved literally in the output.
raw docstring

restructureclj

(restructure m re-map)

Takes an input map and 'restructures' it according to re-map. Restructuring could be thought of as a sort of complement to associative destructuring. It allows you to reshape and transform the data in the input map. This is accomplished by building a map (in re-map) with the desired structure, with values that describe where to get the desired data from the input map, along with optional transforms. Keys and nested maps in re-map will be preserved. Non-map values are extractors - they specify how to retrieve and optionally transform the data from the input map. Extractors can be:

  • non-collection values, which will be treated as keys in the input map and replaced with the associated value
  • vectors, which are treated as tuples of the following-form: [extraction xform-or-val :or? default?]
    • If extraction is a vector, it will retrieve the associated value from the input map as with get-in.
    • If extraction is a map, it can be used to extract multiple values to be passed to the transform, as described below.
    • If extraction is the special-case keyword ::literal (as is the case when one calls literal) then the value of xform-or-val will be used as the literal value.
    • nil values will be passed to transforms.
    • After extraction and any xform, an :or keyword followed by a default value will be used in case of nil.
    • Otherwise it will be treated as a key, as in an extractor. The map version of extraction takes this form: {:ks [key-names-or-nested-vectors] :defaults [optional-defaults]} The values of the extracted keys will be passed, in the order specified, to the transform function. Any missing keys will have nil values. If xform function is provided, it will be called on the value to transform. If a key is missing from the input map or the supplied transformation function returns nil, it will not be included in the output map. ex: (restructure {:a 1 :b 2 :c 3 :d {:e 4}} {:bb {:cc [:a inc] :dd (literal "hi")} :ee [{:ks [:b :c]} max] :ff [{:ks [:f] :defaults [5]} inc] :gg [[:d :e]] :hh [:h :or 12] :ii [{:ks [:h]} :or 13]}) => {:bb {:cc 2, :dd "hi"} :ee 3 :ff 6 :gg 4 :hh 12 :ii 13}
Takes an input map and 'restructures' it according to re-map.
Restructuring could be thought of as a sort of complement to
associative destructuring. It allows you to reshape and transform
the data in the input map.
This is accomplished by building a map (in re-map) with the desired
structure, with values that describe where to get the desired data
from the input map, along with optional transforms. Keys and nested
maps in re-map will be preserved. Non-map values are extractors -
they specify how to retrieve and optionally transform the data from
the input map.
Extractors can be:
 * non-collection values, which will be treated as keys in the
   input map and replaced with the associated value
 * vectors, which are treated as tuples of the following-form:
   [extraction xform-or-val :or? default?]
   * If extraction is a vector, it will retrieve the associated
     value from the input map as with `get-in`.
   * If extraction is a map, it can be used to extract multiple
     values to be passed to the transform, as described below.
   * If extraction is the special-case keyword ::literal (as is
     the case when one calls `literal`) then the value of
     xform-or-val will be used as the literal value.
   * nil values will be passed to transforms.
   * After extraction and any xform, an :or keyword followed by
     a default value will be used in case of nil.
   * Otherwise it will be treated as a key, as in an extractor.
   The map version of extraction takes this form:
     {:ks [key-names-or-nested-vectors]
      :defaults [optional-defaults]}
   The values of the extracted keys will be passed, in the order
   specified, to the transform function. Any missing keys will
   have nil values.
If xform function is provided, it will be called on the value to
transform. If a key is missing from the input map or the supplied
transformation function returns nil, it will not be included in the
output map.
ex:
(restructure {:a 1 :b 2 :c 3 :d {:e 4}}
             {:bb {:cc [:a inc]
                   :dd (literal "hi")}
              :ee [{:ks [:b :c]} max]
              :ff [{:ks [:f] :defaults [5]} inc]
              :gg [[:d :e]]
              :hh [:h :or 12]
              :ii [{:ks [:h]} :or 13]})
 => {:bb {:cc 2, :dd "hi"} :ee 3 :ff 6 :gg 4 :hh 12 :ii 13}
raw docstring

val-mapclj

(val-map f m)

Maps function f over the values of map m

Maps function f over the values of map m
raw docstring

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

× close