{"id":15225217,"url":"https://github.com/mlms13/bs-nonempty","last_synced_at":"2025-04-09T19:10:06.413Z","repository":{"id":143866641,"uuid":"147262084","full_name":"mlms13/bs-nonempty","owner":"mlms13","description":"NonEmpty type with Array and List implementations for ReasonML and OCaml","archived":false,"fork":false,"pushed_at":"2018-10-23T04:40:45.000Z","size":89,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-09T19:09:54.819Z","etag":null,"topics":["bucklescript","collections","functional-programming","list","nonemptylist","ocaml","reasonml"],"latest_commit_sha":null,"homepage":"","language":"OCaml","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mlms13.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2018-09-03T23:11:44.000Z","updated_at":"2019-02-14T18:32:54.000Z","dependencies_parsed_at":null,"dependency_job_id":"3514786f-dd98-4d14-a35d-c56dc6c4f391","html_url":"https://github.com/mlms13/bs-nonempty","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlms13%2Fbs-nonempty","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlms13%2Fbs-nonempty/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlms13%2Fbs-nonempty/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlms13%2Fbs-nonempty/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mlms13","download_url":"https://codeload.github.com/mlms13/bs-nonempty/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248094992,"owners_count":21046770,"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":["bucklescript","collections","functional-programming","list","nonemptylist","ocaml","reasonml"],"created_at":"2024-09-28T18:05:11.059Z","updated_at":"2025-04-09T19:10:06.405Z","avatar_url":"https://github.com/mlms13.png","language":"OCaml","readme":"# bs-nonempty\n\nThis small library provides implementations of `NonEmptyList` and `NonEmptyArray`: collection structures that guarantee you'll have at least one value. Additionally, you can build on top of the `NonEmptyBase` module to make a `NonEmpty*` version of your own collection type.\n\n## Installation\n\n**Install via npm:**\n\n`npm install --save bs-nonempty`\n\n**Update your bsconfig.json**\n\n```\n\"bs-dependencies\": [\n  \"bs-nonempty\"\n],\n```\n\n## Usage\n\nThe following demonstrates the API for using this library with `List`, but from these examples, it should be pretty easy to figure out how the `NonEmptyArray` version works.\n\n**Construct a NonEmptyList**\n\nFor constructing a new `NonEmptyList.t`, you can use `make`, `pure`, `cons`, and `fromT`. You can turn your `NonEmptyList.t` into a `list` using `toT`. The signatures of those functions look like:\n\n```reason\nlet make: ('a, list('a)) =\u003e NonEmptyList.t('a);\n```\n\n```reason\nlet pure: ('a) =\u003e NonEmptyList.t('a);\nlet cons: ('a, NonEmptyList.t('a)) =\u003e NonEmptyList.t('a);\n```\n\n```reason\nlet fromT: list('a) =\u003e option(NonEmptyList.t('a));\nlet toT: NonEmptyList.t('a) =\u003e list('a);\n```\n\nYou can use those functions like this:\n\n```reason\n/* \"import\" from NonEmptyList */\nlet (make, pure, cons, head, tail, fromT, toT) =\n  NonEmptyList(make, pure, cons, head, tail, fromT, toT);\n\nlet myNel = pure(3);\nhead(myNel); /* 3 -- Note that this is not Some(3) */\ntail(myNel); /* [] */\n\nmake(3, [2, 1]) == cons(3, cons(2, pure(1)));\ntoT(make(3, [2, 1])) == [3, 2, 1];\n\nfromT([\"A\"]) == Some(make(\"A\", [])) == Some(pure(\"A\"));\nfromT([]) == None;\n```\n\n**Map, fold (reduce), and more**\n\n```reason\nlet map: ('a =\u003e 'b, NonEmptyList.t('a)) =\u003e NonEmptyList.t('b);\nlet fold_left: (('a, 'b) =\u003e 'a, 'a, NonEmptyList.t('b)) =\u003e 'a;\nlet foldl1: (('a, 'a) =\u003e 'a, NonEmptyList.t('a)) =\u003e 'a;\n\nlet myNel = make(0, [1, 2, 3, 4]);\nmap(string_of_int, myNel); /* == make(\"0\", [\"1\", \"2\", \"3\", \"4\"]) */\nfold_left((+), 0, myNel); /* 10 */\nfoldl1((+), myNel); /* 10 */\n```\n\n```reason\nlet append: (NonEmptyList.t('a), NonEmptyList.t('a)) =\u003e NonEmptyList.t('a);\nlet join: (NonEmptyList.t(NonEmptyList.t('a))) =\u003e NonEmptyList.t('a);\nlet reverse: NonEmptyList.t('a) =\u003e NonEmptyList.t('a);\nlet length: NonEmptyList.t('a) =\u003e int;\n```\n\n## Typeclasses\n\nNote: If \"semigroup\" is a word that freaks you out, you can ignore this entire section. You already know more than enough to use this library. But if you're already familiar with `bs-abstract`, the following might come in handy.\n\n`NonEmpty` is built on top of the great work in [bs-abstract](https://github.com/Risto-Stevcev/bs-abstract). Every `NonEmpty*` implementation (currently List and Array) is a member of the following typeclasses (which can be accessed like `NonEmptyList.Functor.map`):\n\n- [MAGMA_ANY](https://github.com/Risto-Stevcev/bs-abstract/blob/v0.16.0/src/interfaces/Interface.re#L18-L21) and [SEMIGROUP_ANY](https://github.com/Risto-Stevcev/bs-abstract/blob/v0.16.0/src/interfaces/Interface.re#L25) with infix `append` (e.g. `NonEmptyList.Infix.(\u003c:\u003e)`)\n- [FUNCTOR](https://github.com/Risto-Stevcev/bs-abstract/blob/v0.16.0/src/interfaces/Interface.re#L78-L81) with infix `map` (e.g. `NonEmptyList.Infix.(\u003c$\u003e)`)\n- [APPLY](https://github.com/Risto-Stevcev/bs-abstract/blob/v0.16.0/src/interfaces/Interface.re#L83-L86) and [APPLICATIVE](https://github.com/Risto-Stevcev/bs-abstract/blob/v0.16.0/src/interfaces/Interface.re#L88-L91) with infix `apply` (e.g. `NonEmptyList.Infix.(\u003c*\u003e)`)\n- [MONAD](https://github.com/Risto-Stevcev/bs-abstract/blob/v0.16.0/src/interfaces/Interface.re#L93-L96) with infix `flat_map` (e.g. `NonEmptyList.Infix.(\u003e\u003e=)`)\n\nAdditionally, to roll your own `NonEmpty*` type, the underlying container type needs to be a member of [MONOID_ANY](https://github.com/Risto-Stevcev/bs-abstract/blob/v0.16.0/src/interfaces/Interface.re#L33-L36), [APPLICATIVE](https://github.com/Risto-Stevcev/bs-abstract/blob/v0.16.0/src/interfaces/Interface.re#L88-L91), and [FOLDABLE](https://github.com/Risto-Stevcev/bs-abstract/blob/v0.16.0/src/interfaces/Interface.re#L113-L122) (as well as provide implementations for `head`, `tail`, and `length` functions). See the implementations of `NonEmptyList` and `NonEmptyArray` for examples.\n\n## Contributing\n\n1. Fork and clone this repository\n2. `npm install` to grab `bs-abstract` and any dev dependencies\n3. Add features (and tests!) as appropriate\n4. `npm run test`\n\nHere are some things worth contributing:\n\n- `fold_right` implementation so we can be a member of `FOLDABLE`\n- `EQ` if the underlying `'a` is a member of `EQ`\n- `TRAVERSABLE` if the underlying `'a` is a member of `APPLICATIVE`\n- docblock comments so we can automate the documentation\n- Any extra utility functions or `NonEmptyOtherCollectionType` implementations\n\n## License\n\nReleased under the MIT license. See `LICENSE`.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmlms13%2Fbs-nonempty","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmlms13%2Fbs-nonempty","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmlms13%2Fbs-nonempty/lists"}