transducer

Clojure-inspired transducers for composable, reusable transformations

Files

FileDescription
kit.tomlPackage manifest with metadata and dependencies
src/transducer.kitCore transducers: map, filter, compose, partition, fold
tests/transducer.test.kitTests for composition, stateful ops, and partitioning
examples/basic.kitCore transducers and composition patterns
examples/data-pipeline.kitMulti-stage pipelines, batching, and early termination
examples/word-count.kitMapReduce-style text analysis with transducers
LICENSEMIT license file

Architecture

Transducer Composition

Transducers are composable transformation pipelines that separate the "what" from the "how":

flowchart LR A[Input] --> B[map] B --> C[filter] C --> D[take] D --> E[Reducing Function] E --> F[Output] style B fill:#f9f,stroke:#333 style C fill:#f9f,stroke:#333 style D fill:#f9f,stroke:#333

Transducer vs Traditional

flowchart TB subgraph Traditional["Traditional (multiple passes)"] A1[List] -->|map| B1[New List] B1 -->|filter| C1[New List] C1 -->|take| D1[New List] end subgraph Transducer["Transducer (single pass)"] A2[Input] -->|composed xform| B2[Output] end

Dependencies

No Kit package dependencies.

Installation

kit add gitlab.com/kit-lang/packages/kit-transducer.git

Usage

import Kit.Transducer

License

MIT License - see LICENSE for details.

Exported Functions & Types

map

(a -> b) -> Transducer a b

filter

(a -> Bool) -> Transducer a a

remove

(a -> Bool) -> Transducer a a

cat

Transducer (List a) a

mapcat

(a -> List b) -> Transducer a b

keep

(a -> Option b) -> Transducer a b

compose

List Transducer -> Transducer a b

transduce

Transducer a b -> (c -> b -> c) -> c -> List a -> c

into

Transducer a b -> List a -> List b

take-into

Int -> List a -> List a

take-xf

Int -> Transducer a b -> List a -> List b

drop-into

Int -> List a -> List a

drop-xf

Int -> Transducer a b -> List a -> List b

take-while-into

(a -> Bool) -> List a -> List a

take-while-xf

(b -> Bool) -> Transducer a b -> List a -> List b

drop-while-into

(a -> Bool) -> List a -> List a

drop-while-xf

(b -> Bool) -> Transducer a b -> List a -> List b

dedupe-into

List a -> List a

dedupe-xf

Transducer a b -> List a -> List b

distinct-into

List a -> List a

distinct-xf

Transducer a b -> List a -> List b

interpose-into

a -> List a -> List a

interpose-xf

b -> Transducer a b -> List a -> List b

map-indexed

(Int -> a -> b) -> Transducer a b

map-indexed-into

(Int -> a -> b) -> List a -> List b

count

Transducer a b -> List a -> Int

sum

Transducer a Int -> List a -> Int

any?

Transducer a b -> List a -> Bool

none?

Transducer a b -> List a -> Bool

first

Transducer a b -> List a -> Option b

last

Transducer a b -> List a -> Option b

partition

Int -> List a -> List (List a)

partition-xf

Int -> Transducer a b -> List a -> List (List b)

partition-by

(a -> b) -> List a -> List (List a)

partition-by-xf

(b -> c) -> Transducer a b -> List a -> List (List b)

pipe

List Transducer -> List a -> List b