DA.Either Samples

Hello, good evening! I would like to ask on how we could implement DA.Either functions, since I’m having a hard time finding some sample codes.

Thanks!

2 Likes

Hi @carleslabon,

Implementing them yourself based on pattern matching may be a good learning experience. For an example syntax, if you wanted to convert an Either to a list, with an empty list for a Right and a single-element list for a Left, you would write:

keepLeft: Either a b -> [a]
keepLeft e = case e of
  Right _ -> []
  Left a -> [a]

If you’re not after the exercise but just want to see how we did it, you can simply look at the source code for the DA.Either module.

5 Likes

Hello @Gary_Verhaegen,

I’ll try this one on my end.

Thanks.

2 Likes