Today I Learned

A Hashrocket project

Ready to join Hashrocket? Find Openings here and apply today.

Elixir unique numbers

I just found out that Elixir has a function that gets an unique_integer/1. This is very useful for Factories if you want to implement something like sequences to avoid errors due to database unique constraints.

iex(1)> System.unique_integer(~w[monotonic positive]a) 
1
iex(2)> System.unique_integer(~w[monotonic positive]a) 
2
iex(3)> System.unique_integer(~w[monotonic positive]a) 
3
Looking for help? At Hashrocket, we 💜 Elixir! From our many Elixir client projects, to sponsoring the Chicago Elixir Meetup, to the source code for this application, we are invested in this community. Contact us today to talk about your Elixir project.