{"id":13726624,"url":"https://github.com/draftbit/bs-js-collections","last_synced_at":"2025-02-27T12:40:04.170Z","repository":{"id":72463199,"uuid":"289994384","full_name":"draftbit/bs-js-collections","owner":"draftbit","description":"Bindings to JavaScript primitive Set and Map types","archived":false,"fork":false,"pushed_at":"2024-10-28T12:53:06.000Z","size":200,"stargazers_count":12,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-25T12:11:24.364Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"ReScript","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/draftbit.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-08-24T17:28:38.000Z","updated_at":"2024-11-05T00:36:27.000Z","dependencies_parsed_at":null,"dependency_job_id":"a0f0606a-5d5d-4fb5-ae4e-d1dd4f9dd9d5","html_url":"https://github.com/draftbit/bs-js-collections","commit_stats":null,"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/draftbit%2Fbs-js-collections","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/draftbit%2Fbs-js-collections/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/draftbit%2Fbs-js-collections/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/draftbit%2Fbs-js-collections/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/draftbit","download_url":"https://codeload.github.com/draftbit/bs-js-collections/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241014212,"owners_count":19894210,"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-08-03T01:03:14.986Z","updated_at":"2025-02-27T12:40:04.133Z","avatar_url":"https://github.com/draftbit.png","language":"ReScript","funding_links":[],"categories":["Reason"],"sub_categories":[],"readme":"# `bs-js-collections`\n\nBindings to primitive JavaScript `Set` and `Map` types for\nBuckleScript/ReScript.\n\nIn addition to bindings to the native API, this library adds a number\nof functions useful for pure functional programming, such as:\n\n* Conversion to/from various data structures such as arrays, lists,\n  dicts and `Belt` data structures\n* `map`, `keep`, `reduce`, including `*WithKey` versions for the Map type\n* Set operations such as `union`, `intersection` and `diff`\n\nIt is largely influenced by `Belt`, following similar naming\nconventions and favoring fast-pipe argument order\n(i.e. significant-data-first).\n\n## Examples\n\n### Sets\n\n```reason\n// Construct empty, with a single element, or from an array\nlet myEmptySet = JsSet.empty();\nlet mySetWithOneString = JsSet.singleton(\"hello!\");\nlet myIntSet = [|1, 2, 3|]-\u003eJsSet.fromArray;\n\n// Mutably add some values to the set\n[|3, 4, 5|]-\u003eBelt.Array.forEach(myIntSet-\u003eJsSet.addMut);\n\n// Mutably delete values from the set\nmyIntSet-\u003eJsSet.deleteMut(1);\n\n// Map functions over the set\nlet myStringSet = myIntSet-\u003eJsString.map(string_of_int);\n\n// Filter the set\nJs.log(myIntSet-\u003ekeep(i =\u003e i \u003c 3)); // { 1, 2 }\n\n// Filter and map the set\nJs.log(myIntSet-\u003ekeepMap(i =\u003e i == 2 ? None : Some(i-\u003estring_of_int))); // { '1', '3' }\n\nJs.log(myIntSet-\u003eJsSet.size); // 2\n```\n\n### Maps\n\n```reason\nlet myStringMap = JsMap.fromArray([|(\"x\", 1), (\"y\", 2)|]);\nmyStringMap-\u003eJsMap.delete(\"x\");\nJs.log(myStringMap-\u003eJsMap.size); // 1\nJs.log(myStringMap-\u003eJsMap.has(\"y\")); // true\nJs.log(myStringMap-\u003eJs.Map.get(\"y\")); // 2\n```\n\nSee the `.rei` files for more tails, and unit tests examples of usage.\nIn general we try to follow naming conventions similar to `Belt` and\na pipe-first style.\n\n## Usable types\n\nOne of the advantages of `JsMap.t` over `Js.Dict.t` is to allow arbitrary\nkey types (e.g. numbers). Similarly for the values allowable\nin `JsSet.t`. The compiler will set values and map keys to be any type,\nbut in practice only certain types will work. In particular, it must be\na type at runtime that JavaScript is able to handle.\n\nThe rule of thumb is that for map keys and set values, it must be a type\nwhich, at runtime, takes the form of an int, a string, a boolean, etc. This\nmeans that most enums are fine, as are opaque wrapper types.\n\n**Do not** use records, lists, arrays, tuples, etc.\n\n**Avoid** optional types in general or at the least provide extra testing\nif it's unavoidable.\n\n## Commands/scripts\n\n```\nyarn re:build\nyarn re:clean\nyarn re:watch\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdraftbit%2Fbs-js-collections","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdraftbit%2Fbs-js-collections","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdraftbit%2Fbs-js-collections/lists"}