NonEmpty.Types
- carleslabonOP 2
Hello good evening, I would like to ask the use of NonEmpty.Types and also a sample code to better understand it’s usage, since I’m having a hard time looking for some reference.
Thanks!
- bernhard 2
@carleslabon have you had a look at the
DA.NonEmptydocs?The page for
DA.NonEmpty.Typesreally just gives you some insight into theNonEmptytype so you can pattern match on it better.In short,
NonEmptyis a nonempty list and you can treat it like a list in almost all cases. The difference is that functions likeheadare not partial, and that you need to pattern match differently. So instead of having to do constructs likecase xs of [] -> ... hd::tl -> ...you can just do
let hd = xs.hd tl = xs.tl ...or, of course use
xs.hdandxs.tldirectly. - Gary_Verhaegen 2
Hi @carleslabon,
From the documentation (emphasis mine):
This module contains the type for non-empty lists so we can give it a stable package id. This is reexported from DA.NonEmpty so you should never need to import this module.
You can safely ignore the
DA.NonEmpty.Typesmodule. As @bernhard explained,DA.NonEmptyis really just there to add a type constraint on the fact that the list you expect is not empty. - carleslabon 2
Yes I had a look for DA.NonEmpty docs, I just thought that DA.NonEmpty.Types is a seperate module, haha. Thanks @bernhard!
- carleslabon 2
Noted on this one, thanks @Gary_Verhaegen!