ProductPromotion
Logo

Elixir

made by https://0x3d.site

GitHub - lnikkila/elixir-range-extras: Elixir range utilities: constant-time random sampling and set operations.
Elixir range utilities: constant-time random sampling and set operations. - lnikkila/elixir-range-extras
Visit Site

GitHub - lnikkila/elixir-range-extras: Elixir range utilities: constant-time random sampling and set operations.

GitHub - lnikkila/elixir-range-extras: Elixir range utilities: constant-time random sampling and set operations.

RangeExtras

Hex.pm Build status Test coverage

Elixir range utilities: constant-time random sampling and set operations.

Installation

First, please make sure that you’re running Erlang/OTP 18.0 or newer.

Add range_extras to your list of dependencies in mix.exs:

def deps do
  [{:range_extras, "~> 0.1.0"}]
end

Run mix deps.get.

Read the latest documentation at https://hexdocs.pm/range_extras/.

Set operations

  • union/2
  • difference/2
  • intersection/2

These functions take two ranges and return a list of zero to two ranges:

iex> RangeExtras.union(1..4, 3..5)
[1..5]

iex> RangeExtras.difference(8..1, 4..4)
[8..5, 3..1]

iex> RangeExtras.intersection(8..1, -4..0)
[]

They’re implemented as simple cond clauses that match on the start and end values of the ranges, so they run in constant time.

Ranges are always inclusive.

The direction of the resulting ranges is the same as the direction of the first given range:

iex> RangeExtras.union(1..4, 3..5)
[1..5]

iex> RangeExtras.union(4..1, 3..5)
[5..1]

Random sampling

  • random/1

Works in the same way as Enum.random/1, but runs in constant time as well since it only uses the start and end values of the range.

The implementation uses Erlang’s :rand module. You don’t need to seed the generator like you have to currently do with Enum.random/1 that uses :random instead.

(The development version of Elixir now uses :rand.)

Licence

ISC License (ISC)

Copyright © 2015 Leo Nikkilä

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

Articles
to learn more about the elixir concepts.

Resources
which are currently available to browse on.

mail [email protected] to add your project or resources here 🔥.

FAQ's
to know more about the topic.

mail [email protected] to add your project or resources here 🔥.

Queries
or most google FAQ's about Elixir.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory