{"id":23879339,"url":"https://github.com/ceedubs/unison-foldl","last_synced_at":"2026-02-17T22:31:00.722Z","repository":{"id":142075314,"uuid":"282675813","full_name":"ceedubs/unison-foldl","owner":"ceedubs","description":"Composable, streaming, and efficient left folds","archived":false,"fork":false,"pushed_at":"2021-10-19T15:18:19.000Z","size":1736,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-31T00:39:32.488Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ceedubs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-07-26T15:16:29.000Z","updated_at":"2021-10-19T15:18:21.000Z","dependencies_parsed_at":"2023-07-09T05:31:17.276Z","dependency_job_id":null,"html_url":"https://github.com/ceedubs/unison-foldl","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ceedubs/unison-foldl","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ceedubs%2Funison-foldl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ceedubs%2Funison-foldl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ceedubs%2Funison-foldl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ceedubs%2Funison-foldl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ceedubs","download_url":"https://codeload.github.com/ceedubs/unison-foldl/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ceedubs%2Funison-foldl/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29560695,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-17T21:50:49.831Z","status":"ssl_error","status_checked_at":"2026-02-17T21:46:15.313Z","response_time":100,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":[],"created_at":"2025-01-03T22:51:34.514Z","updated_at":"2026-02-17T22:31:00.686Z","avatar_url":"https://github.com/ceedubs.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# foldl\n\n`foldl` is a Unison module that allows you to compose strict left folds such that\ntheir results can be combined in a single pass of input data.\n\nThis is a partial Unison port of the Haskell [foldl](https://hackage.haskell.org/package/foldl-1.1.2)\nmodule, and you'll find much better documentation there.\n\n## getting the dependency\n\nIn a `ucm` session, run the following. Feel free to change `external.foldl` to whatever\nnamespace you prefer.\n\n    .\u003e pull https://github.com/ceedubs/unison-foldl.git:.trunk external.foldl\n\n## usage\n\n### simple folds\n\nOne of the simplest folds that you can perform is to simply count the number of\ninput elements.\n\n    folds.Nat.count.examples.nonempty = List.fold count [1, 2, 3]\n    ↳ 3\n\nSimilarly you can calculate the sum of the input.\n\n    folds.Nat.sum.examples.nonempty = List.fold Nat.sum [1, 2, 3]\n    ↳ 6\n\n### composite folds\n\nYou can compose folds using [applicative](http://hackage.haskell.org/package/base-4.14.0.0/docs/Control-Applicative.html)-style\ncomposition. The combined results of these folds will be calculated in a single\npass of the data.\n\n    Fold.ap.examples.paired = List.fold (pair \u003c$\u003e Nat.sum \u003c*\u003e count) [1, 2, 3]\n    ↳ (6, 3)\n\n\n```\nFold.ap.examples.badAverage =\n  use Nat /\n  (/) \u003c$\u003e Nat.sum \u003c*\u003e count\n\n```\n\n\nThere are a couple of issues with this average function. Since it is using `Nat`\ndivision, the result may be truncated. Also it will throw a `divide by zero` error\nif you pass in an empty list. You are better off using the `average` function provided\nby this library. The `average` function expects the input to have type `Float`,\nwhich we can accomplish with a `premap` on the input to the `average` fold.\n\n```\nFold.premap.examples.natToFloat =\n  List.fold (premap Nat.toFloat average) [1, 2, 3, 4]\n\n↳ Some 2.5\n\n```\n\nThe result type is `Optional Float`, because we might not be able to calculate the\naverage if there are zero items in the input. If you want to map the output of the\nfold in addition to pre-mapping the input, you can use `dimap` and supply both.\nLet's map the output to return `0.0` instead of `None` if there are no items in\nthe input.\n\n```\nFold.dimap.examples.natAverageOrZero =\n  dimap Nat.toFloat (orDefault 0.0) average\n\nFold.dimap.examples.natAverageOrZeroNonemptyFold =\n  List.fold natAverageOrZero [1, 2, 3, 4]\n\n↳ 2.5\n\nFold.dimap.examples.natAverageOrZeroEmptyFold = List.fold natAverageOrZero []\n\n↳ 0.0\n\n```\n\n## module API\n\nHere is a list of the terms included in this library.\n\n```haskell\ntype Fold a b\ntype Fold' a b x\nFold'.Fold' : (x -\u003e a -\u003e x) -\u003e x -\u003e (x -\u003e b) -\u003e Fold' a b x\nFold.\u003c$\u003e : (b -\u003e c) -\u003e Fold a b -\u003e Fold a c\nFold.\u003c*\u003e : Fold a (b -\u003e c) -\u003e Fold a b -\u003e Fold a c\nFold.Fold : (∀ r. (∀ x. Fold' a b x -\u003e r) -\u003e r) -\u003e Fold a b\nFold.List.fold : Fold a b -\u003e [a] -\u003e b\nFold.Set.fold : Fold a b -\u003e Set a -\u003e b\nFold.dimap : (a -\u003e b) -\u003e (c -\u003e d) -\u003e Fold b c -\u003e Fold a d\nFold.fromFold' : Fold' a b x -\u003e Fold a b\nFold.map : (b -\u003e c) -\u003e Fold a b -\u003e Fold a c\nFold.mkFold : (x -\u003e a -\u003e x) -\u003e x -\u003e (x -\u003e b) -\u003e Fold a b\nFold.premap : (a -\u003e b) -\u003e Fold b c -\u003e Fold a c\nFold.runFoldl : (∀ a b. (b -\u003e a -\u003e b) -\u003e b -\u003e f a -\u003e{𝕖} b) -\u003e Fold a b -\u003e f a -\u003e{𝕖} b\nfind : (a -\u003e Boolean) -\u003e Fold a (Optional a)\nfolds.Float.average : Fold Float (Optional Float)\nfolds.Float.sum : Fold Float Float\nfolds.Nat.count : Fold a Nat\nfolds.Nat.sum : Fold Nat Nat\nfolds.all : (a -\u003e Boolean) -\u003e Fold a Boolean\nfolds.any : (a -\u003e Boolean) -\u003e Fold a Boolean\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fceedubs%2Funison-foldl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fceedubs%2Funison-foldl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fceedubs%2Funison-foldl/lists"}