pigpen.core.fn

*** ALPHA - Subject to change ***

  Function versions of the core pigpen macros. These are useful if you want to
generate more dynamic scripts, where functions are passed as arguments. This
also means that the functions passed must either be quoted manually or with
pigpen.core.fn/trap. See pigpen.core.fn/map* for example.

  Note: You most likely don't want this namespace. Unless you are doing advanced
things, stick to pigpen.core

filter*

added in 0.3.0

(filter* pred relation)(filter* pred opts relation)
Similar to pigpen.core/filter, but is a function and takes a quoted function
as an argument.

  Examples:

    (filter*
      (trap (fn [x] (even? (* x x))))
      data)

  See also: pigpen.core/filter, pigpen.core.fn/trap

fold*

added in 0.3.0

(fold* fold relation)(fold* fold opts relation)
Applies the fold function `fold` to the data. Similar to pigpen.core/fold,
but is a function and `fold` must be quoted.

  Example:

    (fold* '(fold/count) data)

  See also: pigpen.core/fold, pigpen.core.fn/trap

group*

added in 0.3.0

(group* selects f)(group* selects f opts)
Similar to pigpen.core/cogroup, but is a function and takes a quoted function
as an argument. Also takes select clauses as maps.

  Example:

    (group*
      [{:from data1, :by (trap (fn [x] (* x x)))}
       {:from data2, :by 'identity}]
      (trap (fn [k l r] {:key k, :left l, :right r})))

  See also: pigpen.core/group-by, pigpen.core/cogroup, pigpen.core.fn/trap

join*

added in 0.3.0

(join* selects f)(join* selects f opts)
Similar to pigpen.core/join, but is a function and takes a quoted function
as an argument. Also takes select clauses as maps.

  Example:

    (join*
      [{:from data1, :by (trap (fn [x] (* x x)))}
       {:from data2, :by 'identity}]
      (trap (fn [l r] {:left l, :right r})))

  See also: pigpen.core/join, pigpen.core.fn/trap

load-string*

added in 0.3.0

(load-string* location f)(load-string* location requires f)
The base for load-string, load-clj, load-json, etc. The parameters `requires`
and `f` specify a conversion function to apply to each input row. `f` must be
quoted prior to calling load-string*.

  Examples:

    (oad-string*
      "input.txt"
      (trap (fn [x] (subs x 42)))
      data)

  See also: pigpen.core/load-string, pigpen.core.fn/trap

map*

added in 0.3.0

(map* f relation)(map* f opts relation)
Similar to pigpen.core/map, but is a function and takes a quoted function as
an argument.

  Examples:

    (defn do-stuff [f data]
      (map* f data))

    (do-stuff 'inc)

    (do-stuff
      (pigpen.core.fn/trap
        (fn [x] (* x x))))

Note that the above example would not work with pigpen.core/map because f would
be compiled before do-stuff is called.

  See also: pigpen.core/map, pigpen.core.fn/trap

map-indexed*

added in 0.3.0

(map-indexed* f relation)(map-indexed* f opts relation)
Similar to pigpen.core/map-indexed, but is a function and takes a quoted
function as an argument.

  Examples:

    (map-indexed*
      (trap (fn [i x] (* i x)))
      data)

  See also: pigpen.core/map-indexed, pigpen.core.fn/trap

mapcat*

added in 0.3.0

(mapcat* f relation)(mapcat* f opts relation)
Similar to pigpen.core/mapcat, but is a function and takes a quoted function
as an argument.

  Examples:

    (mapcat*
      (trap (fn [x] [(dec x) x (inc x)]))
      data)

  See also: pigpen.core/mapcat, pigpen.core.fn/trap

reduce*

added in 0.3.0

(reduce* f relation)(reduce* f opts relation)
Reduces all data into a single collection and applies f to that collection.
The function `f` must be quoted prior to calling reduce*.

  Example:

    (reduce*
      (trap (fn [xs] (count xs)))
      data)

  See also: pigpen.core/into, pigpen.core/reduce, pigpen.core.fn/trap

set-op*

added in 0.3.0

(set-op* f opts? relations+)
Common base for most set operations. Takes a quoted function that should take
the same number of args as there are relations passed to set-op*. Each of those
args is a sequence of the same values from that relation, similar to a cogroup
where the key-fn is identity. `f` should return a sequence which is then
flattened.

  Example:

    (set-op*
      (trap
        (fn [& args] (mapv count args)))
      data1
      data2
      ...
      dataN)

  See also: pigpen.core/intersection, pigpen.core/difference, pigpen.core.fn/trap

sort*

added in 0.3.0

(sort* comp relation)(sort* key-selector comp relation)(sort* key-selector comp opts relation)
Similar to pigpen.core/sort-by, but is a function and takes a quoted
function as an argument.

  Examples:

    (sort*
      (trap (fn [x] (* x x)))
      :asc
      data)

  See also: pigpen.core/sort, pigpen.core/sort-by, pigpen.core.fn/trap

store-string*

added in 0.3.0

(store-string* location f relation)(store-string* location requires f relation)
The base for store-string, store-clj, store-json, etc. The parameters
`requires` and `f` specify a conversion function to apply to each input row.
`f` must be quoted prior to calling store-string*.

  Examples:

    (store-string*
      "input.txt"
      (trap (fn [x] (with-out-str (clojure.pprint/pprint x))))
      data)

  See also: pigpen.core/store-string, pigpen.core.fn/trap

trap

macro

added in 0.3.0

(trap f)(trap ns f)
Returns a form that, when evaluated, will reconsitiute f in namespace ns, in
the presence of any local bindings. If `ns` is not specified, the current
namespace, *ns*, is used.

  Examples:

    => (trap (fn [x] (* x x)))
    (pigpen.runtime/with-ns pigpen-demo.core
      (fn [x] (* x x)))

    => (let [y (* 21 2)]
         (trap
           (fn [x] (+ x y))))
    (pigpen.runtime/with-ns pigpen-demo.core
      (clojure.core/let [y (quote 42)]
        (fn [x] (+ x y))))

  Note: `ns` must exist as a file that will be in the final deployed uberjar.
        If you are in a temporary namespace in a REPL, it will not be included
        in the rewritten version of the expression.