Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/brandonbloom/transduce
map-state, mapcat-state, etc for state transducers in Clojure
https://github.com/brandonbloom/transduce
Last synced: about 1 month ago
JSON representation
map-state, mapcat-state, etc for state transducers in Clojure
- Host: GitHub
- URL: https://github.com/brandonbloom/transduce
- Owner: brandonbloom
- Created: 2013-06-20T17:36:02.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2014-08-14T21:21:45.000Z (over 10 years ago)
- Last Synced: 2024-10-03T05:10:21.879Z (3 months ago)
- Language: Clojure
- Size: 134 KB
- Stars: 21
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
**NOTE: This library is totally unrelated to Clojure 1.7's new tranducers**
# transduce
A Clojure library providing functions for threading a state accumulator through
a sequence transformation. These state/behavior pairs are sometimes called
"transducers" or "state transducers".The class of transducers which use bounded space are particularly interesting.
They are known as [finite state transducers][1].In particular, this library provides `map-state` and `mapcat-state`, which are
like their stateless namesakes. Also provided is a non-macro variant of
`doseq`, called `each`. Both lazy sequence and reducers versions are available
for all functions.## Usage
```clojure
(require '[transduce.lazy :as t])
;OR: (require '[transduce.reducers :as t])(do
(->> [[:c \a] [:n 3] [:c \b] [:c \c] [:n 1] [:c \d]]
(t/mapcat-state (fn [n [cmd arg]]
(case cmd
:n [arg nil]
:c [n (repeat n arg)]))
1)
(t/each print))
(println))
;=> abbbcccd
;=> nil
```## Installation
Transduce artifacts are [published on Clojars][2].
To depend on this version with Lein, add the following to your `project.clj`:
```clojure
[transduce "0.1.0"]
```## License
Copyright © 2013 Brandon Bloom
Distributed under the Eclipse Public License, the same as Clojure.
[1]: http://en.wikipedia.org/wiki/Finite_state_transducer
[2]: https://clojars.org/transduce