It is 6:45 on a Sunday morning and I am on a train to Tel Aviv, the perfect time to talk about an Elm Package. Today I want to checkout List.SafeList

This is a rather cool package that I have not had the opertunity to use yet. But what it does is allows us to encode a list with its length in the type.

Where this really shines is that in a function like map2 you can map together 2 lists and ensure that their lengths match. In a normal Elm list the extra elements are just ignored.

map2 : (a -> b -> c -> d) -> SafeList a n -> SafeList b n -> SafeList c n

Or Here is the SafeList.head function. Note that it does not return a Maybe, what it does is ensure that there is at least one element in the list with the (OnePlus n) .

head : SafeList a (OnePlus n) -> a

You can also convert SafeLists to normal Lists if you want.

I am looking forward to using this at some point.

If you have a module that you think more people should know about email me “zach at get-finch.com”. You can also sign up for my mailing list to hear about these posts as soon as I write them.