{"id":18357136,"url":"https://github.com/funkia/jabz","last_synced_at":"2025-07-22T08:32:31.262Z","repository":{"id":57279031,"uuid":"64081658","full_name":"funkia/jabz","owner":"funkia","description":"Powerful and practical functional abstractions for JavaScript and TypeScript. Functors, Monads, Traversables and all that jazz.","archived":false,"fork":false,"pushed_at":"2018-06-06T09:55:43.000Z","size":8504,"stargazers_count":89,"open_issues_count":6,"forks_count":7,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-06-03T18:52:26.769Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/funkia.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}},"created_at":"2016-07-24T19:18:32.000Z","updated_at":"2025-02-11T15:48:45.000Z","dependencies_parsed_at":"2022-09-11T18:13:58.371Z","dependency_job_id":null,"html_url":"https://github.com/funkia/jabz","commit_stats":null,"previous_names":["paldepind/jabz"],"tags_count":23,"template":false,"template_full_name":null,"purl":"pkg:github/funkia/jabz","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/funkia%2Fjabz","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/funkia%2Fjabz/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/funkia%2Fjabz/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/funkia%2Fjabz/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/funkia","download_url":"https://codeload.github.com/funkia/jabz/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/funkia%2Fjabz/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264773878,"owners_count":23661755,"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":[],"created_at":"2024-11-05T22:12:57.461Z","updated_at":"2025-07-22T08:32:31.237Z","avatar_url":"https://github.com/funkia.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"\u003cimg align=\"right\" src=\"https://avatars0.githubusercontent.com/u/21360882?v=3\u0026s=200\"\u003e\n\n# Jabz\n\nPowerful and practical abstractions for JavaScript. Functors, monads,\nfoldables, traversables, and all that jazz.\n\n[![Build Status](https://travis-ci.org/funkia/jabz.svg?branch=master)](https://travis-ci.org/funkia/jabz)\n[![codecov](https://codecov.io/gh/funkia/jabz/branch/master/graph/badge.svg)](https://codecov.io/gh/funkia/jabz)\n[![Gitter chat](https://badges.gitter.im/Join_Chat.svg)](https://gitter.im/funkia/General?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge)\n\n## Goals and features\n\n* Be as simple and convenient as possible in usage\n* Allow for performant implementations\n* TypeScript support\n* Batteries included. Provide implementations of often used instances\n  and commonly used utility functions.\n* Do-notation\n* [Seamless instances](#seamless-instances)\n* Comes with files in ES2015 module format for tree-shaking\n\nFor a more detailed introduction to the design of the specification\nand a comparison to Fantasy Land please see [this blog\npost](http://vindum.io/blog/introducing-jabz/).\n\n## Install\n\n```\nnpm install @funkia/jabz\n```\n\n## Documentation\n\nSee [the API documentation](https://funkia.github.io/jabz/) and the\nexample below.\n\nNote that the specification for the abstractions is not written down\nformally yet. But the source code contain TypeScript interfaces that\ndocuments the different required methods. The laws associated with the\nabstractions are as expected if one is familiar with them.\n\n## Example\n\nThis example demonstrates some of what Jabz can do by implementing a\nsimple singly linked list aka. a cons list. \n\n```js\n@monad @traversable\nclass Cons {\n  constructor(v, t) {\n    this.val = v;\n    this.tail = t;\n  }\n  concat(c) {\n    return this === nil ? c : cons(this.val, this.tail.concat(c));\n  }\n  of(b: B) {\n    return cons(b, nil);\n  }\n  chain\u003cB\u003e(f) {\n    return this === nil ? nil : f(this.val).concat(this.tail.chain(f));\n  }\n  traverse\u003cB\u003e(a, f) {\n    return this === nil ? a.of(nil) : lift(cons, f(this.val), this.tail.traverse(a, f));\n  }\n}\nconst nil = new Cons(undefined, undefined);\nfunction cons(a: A, as) {\n  return new Cons(a, as);\n}\nfunction fromArray(as) {\n  return as.length === 0 ? nil : cons(as[0], fromArray(as.slice(1)));\n}\n```\n\nSince `Cons` contains the methods `of` and `chain` it can\nimplement monad. This is done with the `@monad` decorator. JavaScript\ndecorators are just plain old functions so they can also be used\nwithout the decorator syntax\n\n```js\nmonad(Cons);\n```\n\nThe function allows implementations flexibility in what methods they\nchoose to provide. For instance monad can also be implemented by\ndefining a `of`, a `map` and a `chain` method.\n\nSimilar to Monad, Traversable is implemented by defining the\n`traverse` method and using the `traversable` decorator.\n\nWhen we implement Monad Jabz automatically derives implementations for\nFunctor and Applicative. Likewise when we implement Traversable it\nderives Foldable. Thus, Jabz can give us a lot of things for free just\nfrom the few methods the `Cons` class defines.\n\nMap functions over elements in the list.\n```js\nmapTo((n) =\u003e n * n, fromArray([1, 2, 3, 4])); //=\u003e [1, 4, 9, 16]\n```\n\nChange each element in the list to a constant.\n\n```js\nmapTo(8, fromArray([1, 2, 3, 4])); //=\u003e [8, 8, 8, 8]\n```\n\nApply a list of functions to a list of values.\n\n```js\nap(fromArray([(n) =\u003e n * 2, (n) =\u003e n * n]), fromArray(1, 2, 3)); //=\u003e [2, 4, 6, 1, 4, 9]\n```\n\nFolding.\n\n```js\nfoldr((n, m) =\u003e n + m, 3, fromArray([1, 2, 3, 4, 5])); //=\u003e 18\n```\n\nFind an element satisfying a predicate.\n\n```js\nfind((n) =\u003e n \u003e 6, fromArray([1, 8, 3, 7, 5])); //=\u003e just(8)\nfindLast((n) =\u003e n \u003e 6, fromArray([1, 8, 3, 7, 5])); //=\u003e just(7)\n```\n\nWe can convert a cons-list to an array\n\n```js\ntoArray(fromArray([1, 2, 3, 4])); //=\u003e [1, 2, 3, 4]\n```\n\nWe can flatten nested cons-lists.\n\n```js\nflatten(fromArray([fromArray([1, 2]), fromArray([3, 4, 5])])); //=\u003e [1, 2, 3, 4, 5]\n```\n\n## Seamless instances\n\nSeamless instances means that certain native JavaScript types can be\nused as if they implemented the abstractions relevant for them.\n\n* `string`, implements setoid and monoid.\n* `array`, implements setoid, monoid, functor, foldable and traversable.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffunkia%2Fjabz","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffunkia%2Fjabz","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffunkia%2Fjabz/lists"}