{"id":13740724,"url":"https://github.com/giacomocavalieri/tote","last_synced_at":"2025-07-07T21:33:03.353Z","repository":{"id":202974220,"uuid":"708527972","full_name":"giacomocavalieri/tote","owner":"giacomocavalieri","description":"👜 Bags (or multisets) in Gleam","archived":false,"fork":false,"pushed_at":"2024-10-31T06:12:23.000Z","size":36,"stargazers_count":9,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-06-26T19:16:53.300Z","etag":null,"topics":["bag","multiset"],"latest_commit_sha":null,"homepage":"https://hexdocs.pm/tote/","language":"Gleam","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/giacomocavalieri.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}},"created_at":"2023-10-22T20:18:07.000Z","updated_at":"2025-05-24T09:41:27.000Z","dependencies_parsed_at":null,"dependency_job_id":"b62764a7-a7ec-4877-8dbd-8b0523f66db8","html_url":"https://github.com/giacomocavalieri/tote","commit_stats":null,"previous_names":["giacomocavalieri/tote"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/giacomocavalieri/tote","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/giacomocavalieri%2Ftote","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/giacomocavalieri%2Ftote/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/giacomocavalieri%2Ftote/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/giacomocavalieri%2Ftote/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/giacomocavalieri","download_url":"https://codeload.github.com/giacomocavalieri/tote/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/giacomocavalieri%2Ftote/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262509161,"owners_count":23322003,"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":["bag","multiset"],"created_at":"2024-08-03T04:00:51.611Z","updated_at":"2025-07-07T21:33:03.334Z","avatar_url":"https://github.com/giacomocavalieri.png","language":"Gleam","funding_links":[],"categories":["Packages"],"sub_categories":["Data Structures"],"readme":"# tote\n\n[![Package Version](https://img.shields.io/hexpm/v/tote)](https://hex.pm/packages/tote)\n[![Hex Docs](https://img.shields.io/badge/hex-docs-ffaff3)](https://hexdocs.pm/tote/)\n\n👜 Bags (or multisets) in Gleam\n\n\u003e ⚙️ This package works for both the Erlang and JavaScript target\n\n## What's a bag?\n\nA `Bag` is a data structure similar to a set with the difference that it\ncan store multiple copies of the same item.\n\nThis means that you can efficiently check if an element is inside a bag with\nthe [contains](https://hexdocs.pm/tote/tote/bag.html#contains) function,\njust like a set.\nAt the same time, you can ask how many copies of an item are contained inside a\nbag using the [copies](https://hexdocs.pm/tote/tote/bag.html#copies) function.\n\n\u003e If you are curious about implementation details, a `Bag(a)` is nothing\n\u003e more than a handy wrapper around a `Map(a, Int)` that is used to keep\n\u003e track of the number of occurrences of each item.\n\n## Installation\n\nTo add this package to your Gleam project:\n\n```sh\ngleam add tote\n```\n\n## Getting started\n\nAll the bag-related functions are in the `tote/bag` module, so once you've\nimported that you're good to go:\n\n```gleam\nimport gleam/int\nimport gleam/io\nimport tote/bag\n\npub fn main() {\n  let valentino_bag =\n    bag.from_list([\n      \"lipstick\", \"in\", \"my\", \"wh-\", \"wh-\", \"lipstick\",\n      \"in\", \"my\", \"Valentino\", \"white\", \"bag\", \"?!\"\n    ])\n\n  bag.copies(of: \"lipstick\", in: valentino_bag)\n  |\u003e int.to_string\n  |\u003e io.println\n  // -\u003e 2\n}\n```\n\nIf you don't get the Valentino reference,\n[you're welcome!](https://www.youtube.com/watch?v=IzTlPjgJfTk)\n\n## Contributing\n\nIf you think there's any way to improve this package, or if you spot a bug don't\nbe afraid to open PRs, issues or requests of any kind! Any contribution is\nwelcome 💜\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgiacomocavalieri%2Ftote","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgiacomocavalieri%2Ftote","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgiacomocavalieri%2Ftote/lists"}