Proposal: New set of functions for Elixir.Range

106 views
Skip to first unread message

eksperimental

unread,
Feb 15, 2016, 12:23:52 AM2/15/16
to elixir-l...@googlegroups.com
I have created a set of functions for the range module.
Initially, I based my work in functions written by "jdl"
https://github.com/mykewould/crutches/blob/ddf5535d66601f9630bee1807ef38cb57f52b9b4/lib/crutches/range.ex

You can have a look at the module and tests:
https://github.com/eksperimental/elixir/blob/range/lib/elixir/lib/range.ex
https://github.com/eksperimental/elixir/blob/range/lib/elixir/test/elixir/range_test.exs

New functions are: congruent?/2, disjoint?2, contiguous?/2,
intersection/2, member?/2, overlaps?/2, reverse/1, size/1, sort/2,
subset?/2, to_list/2, union/2

Some functions have been taken from MapSet, and other apply exclusively
to Range.

Please let me know what you think of this.

And if there is an interest in adding this Elixir, I will have to
contact the author of the initial functions for release permission.

Cheers

José Valim

unread,
Feb 15, 2016, 4:50:12 AM2/15/16
to elixir-l...@googlegroups.com
I am OK with adding more functions to Range but I would like to hear use cases. Come with a problem where you need those functions and start a discussion. Adding functions for the sake of the function itself is just adding complexity to the stdlib.



José Valim
Skype: jv.ptec
Founder and Director of R&D


--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/20160215122339.1baa83e6.eksperimental%40autistici.org.
For more options, visit https://groups.google.com/d/optout.

Onorio Catenacci

unread,
Feb 15, 2016, 11:06:21 AM2/15/16
to elixir-lang-core
+1 José. A wise approach.  
Message has been deleted
Message has been deleted

Matt Jonas

unread,
Sep 28, 2017, 12:20:17 AM9/28/17
to elixir-lang-core
Here's a use case... 

I have several "catalog" entries, each with a min & max. I'd like to determine the union of these entries. Converting them to Ranges and then getting the union of those would be an intuitive way.

While it's possible to use a MapSet, it feels wasteful as you have to load it up with every number in the range.

José Valim

unread,
Sep 28, 2017, 9:27:02 AM9/28/17
to elixir-l...@googlegroups.com
Hi Matt, of those functions, which one is your use case about? Is it union exclusively?

And would the proposed behaviour of Range.union/2 of returning nil for non-overlapping ranges be desired? You would most likely lose that in those cases (or have to resort to a set anyway).
Founder and 
Director of R&D

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-core+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/430283dc-f5bf-442b-9132-0f9a14a7564a%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages