{"id":19017440,"url":"https://github.com/junkdog/transducers-kotlin","last_synced_at":"2025-04-23T02:49:13.157Z","repository":{"id":57737538,"uuid":"79411642","full_name":"junkdog/transducers-kotlin","owner":"junkdog","description":"transducers for kotlin, adapted from https://gist.github.com/hastebrot/aa7b5366309d42270cc1","archived":false,"fork":false,"pushed_at":"2017-03-31T21:28:26.000Z","size":60,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-23T02:49:07.243Z","etag":null,"topics":["kotlin","transducers"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/junkdog.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-01-19T03:30:17.000Z","updated_at":"2023-09-10T14:17:29.000Z","dependencies_parsed_at":"2022-08-24T14:59:42.551Z","dependency_job_id":null,"html_url":"https://github.com/junkdog/transducers-kotlin","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/junkdog%2Ftransducers-kotlin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/junkdog%2Ftransducers-kotlin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/junkdog%2Ftransducers-kotlin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/junkdog%2Ftransducers-kotlin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/junkdog","download_url":"https://codeload.github.com/junkdog/transducers-kotlin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250360249,"owners_count":21417717,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["kotlin","transducers"],"created_at":"2024-11-08T19:47:01.613Z","updated_at":"2025-04-23T02:49:13.130Z","avatar_url":"https://github.com/junkdog.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/junkdog/transducers-kotlin.svg)](https://travis-ci.org/junkdog/transducers-kotlin)\n\n## Transducers for kotlin\n\nFrom the official [clojure documentation](https://clojure.org/reference/transducers):\n\n\u003e Transducers are composable algorithmic transformations. They are independent from the context of their input and output sources and specify only the essence of the transformation in terms of an individual element. Because transducers are decoupled from input or output sources, they can be used in many different processes - collections, streams, channels, observables, etc. Transducers compose directly, without awareness of input or creation of intermediate aggregates.\n\nRefer to [CHANGELOG.md](https://github.com/junkdog/transducers-kotlin/blob/master/CHANGELOG.md) for latest updates.\n\n\n### Basic usage\n\n```\ntransduce(xf = \u003ctransducer applied to every input\u003e,\n          rf = \u003cwhat we do to the transduced input\u003e,\n          init = \u003cinitial state\u003e,\n          input = \u003citerable or finite sequence\u003e)\n```\n\n\n```kotlin\n// '+' composes transducers\nval composedTransducer = filter { i: Int -\u003e i % 5 == 0 } +\n                         sum { i: Int -\u003e i / 5 }\n    \n// applying transducer + step function to input\ntransduce(xf = composedTransducer,\n          rf = { result, input -\u003e result + input },\n          init = 0,\n          input = (0..20)\n) assertEquals (1 + 2 + 3 + 4)\n```\n\nKotlin-like shorthands for transducing straight into a collection: `listOf`, `setOf`, and\n`mapOf` take _transducer_ and _input_. \n\n```kotlin\nlistOf(xf = copy\u003cInt\u003e() +\n            branch(test = { it % 4 == 0 },\n                   xfTrue  = map { i: Int -\u003e i * 100 },\n                   xfFalse = map { i: Int -\u003e i / 4 } +\n                             distinct() +\n                             map(Int::toString)),\n       input = (1..9)\n) assertEquals listOf(\"0\", 400, 400, \"1\", 800, 800, \"2\")\n```\n\n## New/Experimental Transducers\n_Experimental_ implies transducers not included with [transducers-java](https://github.com/cognitect-labs/transducers-java).\n\n### new regular transducers\n  - `collect`: input into a mutable collection, releases it upon computing the final result.\n  - `debug`: prints debug statements.\n  - `distinct`: no two equal elements shall pass.\n  - `head`: takes the first elements of an iterable input.\n  - `pairCat`: concatenates `Pair\u003cA, Iterable\u003cB\u003e\u003e` into `Pair\u003cA, B\u003e`.\n  - `resultGate`: ensures _completion_ is calculated once, used with branching/muxing transducers.\n  - `sort`: collects and sorts all input.\n  - `tail`: takes the last elements of an iterable input.\n\n### new higher-order transducers\n  - `branch`: routes input through one out of two transducers, based on predicate.\n  - `join`: turns `List\u003cTransducer\u003cA, B\u003e\u003e` into `Transducer\u003cList\u003cA\u003e, B\u003e`.\n  - `mapPair`: creates pairs based on two transducers. \n  - `mux`: input multiplexer, routing input over several transducer paths based on predicates.\n\n### new single item transducers\n  - `count`: number of input.\n  - `sum`: calculates sum, can be parameterized by a function for producing a custom value per input.\n\n\nRefer to the [API documentation][api-docs] and [tests][test-src] for details.\n\n\n## Original source code:\n\nThe code in this repository is based on https://gist.github.com/hastebrot/aa7b5366309d42270cc1,\nwhich in turn was based on the original port from [transducers-java][transducers-java]:\nSpasi's [Transducers.kt][orig-gist1] and [TransducersTest.kt][orig-gist2] from Oct 12, 2014.  \n\n\n## Resources:\n\n- http://clojure.org/transducers\n- http://blog.cognitect.com/blog/2014/8/6/transducers-are-coming\n- https://github.com/cognitect-labs/transducers-java\n\n## Getting started\n\n### Maven\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003enet.onedaybeard.transducers\u003c/groupId\u003e\n    \u003cartifactId\u003etransducers\u003c/artifactId\u003e\n    \u003cversion\u003e0.4.0\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n### Gradle\n\n```groovy\ndependencies { compile \"net.onedaybeard.transducers:transducers:0.4.0\" }\n```\n\n\n [transducers-java]: https://github.com/cognitect-labs/transducers-java\n [test-src]: https://github.com/junkdog/transducers-kotlin/tree/master/src/test/kotlin/net/onedaybeard/transducers\n [orig-gist1]: https://gist.github.com/Spasi/4052e4e8c8d88a7325fb\n [orig-gist2]: https://gist.github.com/Spasi/2a9d7d420b20f37513d5\n [api-docs]: http://junkdog.github.io/apidoc/transducers-0.4.0/net.onedaybeard.transducers/index.html\n \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjunkdog%2Ftransducers-kotlin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjunkdog%2Ftransducers-kotlin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjunkdog%2Ftransducers-kotlin/lists"}