acalejos

acalejos

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

Showing Posts 1 to 1

acalejos

acalejos OP

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.

— All posts loaded —

Where Next? Top

Trending in Announcing Top

woylie
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries. offset-based pagination with...
New
MRdotB
I needed to reuse React components from my Chrome extension in my Phoenix/LiveView backend. I noticed that for Svelte/Vue, there are live...
New
woylie
I released Doggo, a collection of unstyled Phoenix components. https://github.com/woylie/doggo Features Unstyled Phoenix components....
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
anuaralfetahe
Hello Published a new library - ProcessHub! ProcessHub is a library designed to manage process distribution within the Elixir cluster. ...
New
rodloboz
I’ve started working on a new library to run SQL queries and do basic business intelligence. Think “Blazer for Elixir.” Currently it fe...
New

Other Trending Topics Top

mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New
AstonJ
This showed up on my feed.. anyone heard of it? Just hype? Ox Alpha is a reasoning model designed for coding, sustained ag...
New
bartblast
Hey folks, I just published a post about Hologram’s funding and where the project goes next - the short version: Curiosum as Main Spons...
New
CodeSync
:microphone: ElixirConf 2026 - Call for Talks is open! We’re heading to Chicago :united_states: :round_pushpin: In person + virtual :d...
New
Null-logic-0
What IDE or editor are you using for Elixir development? Personally, I use Zed, and I really like it, but sometimes I wish there were a ...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews