NonEmpty.Types

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!

2 Likes

@carleslabon have you had a look at the DA.NonEmpty docs?

The page for DA.NonEmpty.Types really just gives you some insight into the NonEmpty type so you can pattern match on it better.

In short, NonEmpty is a nonempty list and you can treat it like a list in almost all cases. The difference is that functions like head are not partial, and that you need to pattern match differently. So instead of having to do constructs like

case xs of
  [] -> ...
  hd::tl -> ...

you can just do

let
  hd = xs.hd
  tl = xs.tl
...

or, of course use xs.hd and xs.tl directly.

2 Likes

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.Types module. As @bernhard explained, DA.NonEmpty is really just there to add a type constraint on the fact that the list you expect is not empty.

2 Likes

Yes I had a look for DA.NonEmpty docs, I just thought that DA.NonEmpty.Types is a seperate module, haha. Thanks @bernhard!

2 Likes

Noted on this one, thanks @Gary_Verhaegen!

2 Likes