Skip to content
/ redux Public
forked from henrygarner/redux

A Clojure library of reducing function combinators

License

Notifications You must be signed in to change notification settings

metabase/redux

 
 

Repository files navigation

Redux

A Clojure/ClojureScript library of reducing function combinators.

Installation

Add the following dependency to your deps.edn:

{io.github.metabase/redux {:sha "<latest-commit-sha>"}}

Usage

(require '[redux.core :refer [facet fuse with-xform]])

(transduce identity (facet + [dec inc]) (range 5))

;; => [5 15]

(transduce identity (fuse {:a + :b conj}) (range 5))

;; => {:a 10, :b [0 1 2 3 4]}

(def rf
  (facet
    (fuse {:sum  +
           :conj conj})
    [:a :b]))

(transduce identity rf [{:a 1 :b 2} {:a 3 :b 4}])

;; => [{:sum 4, :conj [1 3]} {:sum 6, :conj [2 4]}]


;; Stateful transducers are reset on reducing function initialization

(let [rf (with-xform conj (take 2))]

  ;; Apply the stateful reducing function once...
  (transduce identity rf [1 2 3])

  ;; => [1 2]

  ;; ...twice...

  (transduce identity rf [1 2 3])

  ;; => [1 2]
)

References

Strongly inspired by Tesser.

License

Copyright © 2016 Henry Garner, 2024 Metabase, Inc.

Distributed under the Eclipse Public License version 1.0.

About

A Clojure library of reducing function combinators

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Clojure 100.0%