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:

https://github.com/acalejos/exterval

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 Announcing Top

Hal9000
Here is my first stab at this. README pasted below. https://github.com/Hal9000/elixir_random Comments and critiques are welcome. Thank...
New
Crowdhailer
I have been updating a library that allows you to pipe between functions that use the erlang result tuple convention. Assuming you have ...
New
OvermindDL1
Been making an MLElixir thing (not released yet…) for fun in spare time in the past day. I’m just trying to see how much I can get an ML...
132 14057 106
New
wmnnd
Hi there, for my project DBLSQD, I needed a file storage solution that is a bit more flexible than Arc. Because I thought others might f...
New
treble37
Just looking for a little feedback on a tiny helper library I built - Sometimes I find the need to convert maps with atom keys to maps w...
New
mspanc
I am pleased to announce an initial release of the Membrane Framework - an Elixir-based framework with special focus on processing multim...
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 43487 311
New
tfwright
After working on it for a couple of months and using it in production for most of that time, today I’ve released LiveAdmin, a LiveView ba...
New
benlime
LiveMotion enables high performance animations declared on the server and run on the client. As a follow up to my previous thread A libr...
New
zachdaniel
Ash Framework What is Ash? Ash Framework is a declarative, resource-oriented application development framework for Elixir. A resource can...
New

Other popular topics Top

JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
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 43757 214
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement