https://github.com/mf42-dzh/transduction
Clojure's transducers in Scala.
https://github.com/mf42-dzh/transduction
composable-functions functional-programming library reducers scala transducers
Last synced: 3 days ago
JSON representation
Clojure's transducers in Scala.
- Host: GitHub
- URL: https://github.com/mf42-dzh/transduction
- Owner: MF42-DZH
- License: lgpl-2.1
- Created: 2022-06-11T20:16:46.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2022-06-14T08:31:30.000Z (almost 4 years ago)
- Last Synced: 2023-09-13T01:03:40.070Z (over 2 years ago)
- Topics: composable-functions, functional-programming, library, reducers, scala, transducers
- Language: Scala
- Homepage:
- Size: 1.09 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Transduction
Clojure's [transducers](https://clojure.org/reference/transducers) in Scala.
Inspired by Clojure's implementation (obviously) and [this Haskell
implementation and theory](https://hypirion.com/musings/haskell-transducers).
Documentation can be found [here](https://0xfc963f18dc21.github.io/transduction/).
## What are they?
Transducers are applicable objects that transform reducers. If you've ever
worked with folding or reduction in a functional language, a reducer is
simply a representation of the reduction function used in those functions.
A reducer has three effective signatures:
- **Identity**: The identity of the reducer. Given when no initial value is used
for the reduction. E.g. for integer reducers, 0 is the default identity
for addition reductions, and 1 is the default identity for multiplication
reductions. (`identity: R`)
- **Completion**: The "finaliser" of a reducer. Called upon the result of the
reduction as a final transformation. (`completion: R => R`)
- **Step**: The actual reduction part of a reducer. Called with the current
accumulated reduction and the current item to be reduced. (`stepL: R => A => R`,
`stepR: A => R => R`)
A transducer adds a layer of transformation onto these reducers, and can be both
stateful or stateless. They are also composeable using simple function composition.
This library aims to provide interfaces for creating immutable and mutable state
transducers and the ability to use them.