acalejos

acalejos

Exterval - Inclusive/Exclusive Real Valued Intervals

I was finding myself needing a library to check for real-valued interval memberships. This was from writing libraries whose parameters must adhere to these restrictions, such as regularization terms or learning rates.

The API is simple for interval creation and supports the Enumerable protocol when a interval step is defined.

Here’s a sample of the API:

iex> import Exterval
iex> ~I<[1, 10)//2>
[1, 10)//2
iex> ~I<[1, 10)//2> |> Enum.to_list()
[1.0, 3.0, 5.0, 7.0, 9.0]
iex> ~I<[1, 10)//2> |> Enum.reduce(&+/2)
25.0
iex> ~I<[-1, 3)//-0.5> |> Enum.to_list()
[2.5, 2.0, 1.5, 1.0, 0.5, 0.0, -0.5, -1.0
iex> ~I<[1, 10]> |> Enum.count()
:infinity
iex> ~I<[1, 10)//2> |> Enum.count()
4
iex> ~I<[-2,-2]//1.0> |> Enum.count()
1
iex> ~I<[1,2]//0.5> |> Enum.count()
3
iex> ~I<[-2,-1]//0.75> |> Enum.count()
2

iex> 1 in ~I<[1, 10]>
true
iex> 1 in ~I<[1, 10)//2>
true
iex> 3 in ~I<(1, 10)//2>
true

Feedback is much appreciated :+1:

First Post!

acalejos

acalejos

Finally found time to do a quick write-up about this library and sigils in general: Elevate Your Elixir With Sigils

Also pushed some updates in the form of a v0.2.0 release to allow for string interpolation within the interval creation.

This required changing from ~I to ~i since only lowercase sigils allow for string interpolation. But now you can declare intervals as so:

iex> min = 0
iex> ~i<[#{min + 1}, 10)//2>
[1.0,10.0)//2.0

Currently using this tiny 1-file library to support parameter validation in two of my other libraries and love the simplicity of it so far.

Where Next?

Popular in Libraries Top

marcuslankenau
I feel kind of stuck with the absence of a proper xml library for Elixir. Currently I use SweetXML which was ok for me more or less to pa...
New
hpopp
After just over two years in development, this latest version of Pigeon is what I finally consider done in regards to my original vision ...
New
tompave
Hello there, I would like to share a feature toggles library (AKA feature flags) I’ve been working on. The main package is FunWithFlags...
New
oltarasenko
Dear Elixir community, After a year of development, bug fixes, and improvements, we are proudly ready to share the release of Crawly 0.1...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 35421 110
New
cjen07
parameterized pipe in elixir: |n&gt; edit: negative index in |n&gt; and mixed usage with |&gt; are supported example: use ParamP...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 42633 214
New
Crowdhailer
Experimenting with this code. OK.try do user &lt;- fetch_user(1) cart &lt;- fetch_cart(1) order = checkout(cart, user) save_or...
New
Qqwy
While not as prevalent as in imperative languages, arrays (collections with efficient random element access) are still very useful in Eli...
New
ostinelli
Let’s write a database! Well not really, but I think it’s a little sad that there doesn’t seem to be a simple in-memory distributed KV da...
New

Other popular topics Top

yurko
Here are few pieces of (common) Linux knowledge that we use for reasonably small one server apps. We use Ubuntu but this should work for ...
New
peerreynders
Manning 2016 Halloween weekend sale via Deal of the Day Friday, October 28 - Half off all MEAPs - code WM102816LT Saturday, October 29 ...
326 29600 154
New
Tee
can someone please explain to me how Enum.reduce works with maps
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
johnnyicon
Hi all, I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I'm trying to use Postg...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New

Sub Categories:

We're in Beta

About us Mission Statement