{"id":13509305,"url":"https://github.com/lnikkila/elixir-range-extras","last_synced_at":"2025-03-30T13:31:56.365Z","repository":{"id":57539756,"uuid":"47519294","full_name":"lnikkila/elixir-range-extras","owner":"lnikkila","description":"Elixir range utilities: constant-time random sampling and set operations.","archived":true,"fork":false,"pushed_at":"2015-12-07T17:51:24.000Z","size":12,"stargazers_count":8,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-13T11:49:12.159Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://hexdocs.pm/range_extras/","language":"Elixir","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/lnikkila.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":"2015-12-07T00:05:00.000Z","updated_at":"2023-01-28T08:55:28.000Z","dependencies_parsed_at":"2022-09-13T08:31:54.957Z","dependency_job_id":null,"html_url":"https://github.com/lnikkila/elixir-range-extras","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lnikkila%2Felixir-range-extras","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lnikkila%2Felixir-range-extras/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lnikkila%2Felixir-range-extras/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lnikkila%2Felixir-range-extras/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lnikkila","download_url":"https://codeload.github.com/lnikkila/elixir-range-extras/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246323952,"owners_count":20759056,"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-01T02:01:05.970Z","updated_at":"2025-03-30T13:31:56.128Z","avatar_url":"https://github.com/lnikkila.png","language":"Elixir","funding_links":[],"categories":["Text and Numbers"],"sub_categories":[],"readme":"# RangeExtras\n\n[![Hex.pm][hexpm-badge]][hexpm]\n[![Build status][circleci-badge]][circleci]\n[![Test coverage][coveralls-badge]][coveralls]\n\n**Elixir range utilities: constant-time random sampling and set operations.**\n\n## Installation\n\nFirst, please make sure that you’re running Erlang/OTP 18.0 or newer.\n\nAdd `range_extras` to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [{:range_extras, \"~\u003e 0.1.0\"}]\nend\n```\n\nRun `mix deps.get`.\n\nRead the latest documentation at \u003chttps://hexdocs.pm/range_extras/\u003e.\n\n## Set operations\n\n- `union/2`\n- `difference/2`\n- `intersection/2`\n\nThese functions take two ranges and return a list of zero to two ranges:\n\n```elixir\niex\u003e RangeExtras.union(1..4, 3..5)\n[1..5]\n\niex\u003e RangeExtras.difference(8..1, 4..4)\n[8..5, 3..1]\n\niex\u003e RangeExtras.intersection(8..1, -4..0)\n[]\n```\n\nThey’re implemented as simple `cond` clauses that match on the start and end\nvalues of the ranges, so they run in constant time.\n\nRanges are always inclusive.\n\nThe direction of the resulting ranges is the same as the direction of the first\ngiven range:\n\n```elixir\niex\u003e RangeExtras.union(1..4, 3..5)\n[1..5]\n\niex\u003e RangeExtras.union(4..1, 3..5)\n[5..1]\n```\n\n## Random sampling\n\n- `random/1`\n\nWorks in the same way as `Enum.random/1`, but runs in constant time as well\nsince it only uses the start and end values of the range.\n\nThe implementation uses Erlang’s `:rand` module. You don’t need to seed the\ngenerator like you have to currently do with `Enum.random/1` that uses\n`:random` instead.\n\n(The development version of Elixir now uses `:rand`.)\n\n## Licence\n\n\u003e ISC License (ISC)\n\u003e\n\u003e Copyright © 2015 Leo Nikkilä\n\u003e\n\u003e Permission to use, copy, modify, and/or distribute this software for any\n\u003e purpose with or without fee is hereby granted, provided that the above \n\u003e copyright notice and this permission notice appear in all copies.\n\u003e\n\u003e THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\n\u003e REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\n\u003e AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\n\u003e INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\n\u003e LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\n\u003e OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\n\u003e PERFORMANCE OF THIS SOFTWARE.\n\n[hexpm]: https://hex.pm/packages/range_extras\n[hexpm-badge]: https://img.shields.io/hexpm/v/range_extras.svg\n\n[circleci]: https://circleci.com/gh/lnikkila/elixir-range-extras\n[circleci-badge]: https://img.shields.io/circleci/project/lnikkila/elixir-range-extras.svg\n\n[coveralls]: https://coveralls.io/github/lnikkila/elixir-range-extras\n[coveralls-badge]: https://img.shields.io/coveralls/lnikkila/elixir-range-extras.svg\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flnikkila%2Felixir-range-extras","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flnikkila%2Felixir-range-extras","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flnikkila%2Felixir-range-extras/lists"}