Skip to content
CCPEDIAby Unity Nodes
Discussions/App Development/DA.Either SamplesForum ↗

DA.Either Samples

App Development3 posts345 views9 likesLast activity Sep 2020
CA
carleslabonOP
Sep 2020

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!

GA
Gary_Verhaegen
Sep 2020

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.

CA
carleslabon
Sep 2020

Hello @Gary_Verhaegen,

I’ll try this one on my end.

Thanks.

← Back to Discussions