generic-maybe

A generic version of Data.Maybe

https://github.com/jfischoff/generic-maybe

Latest on Hackage:0.3.0.4

This package is not currently in any snapshots. If you're interested in using it, we recommend adding it to Stackage Nightly. Doing so will make builds more reliable, and allow stackage.org to host generated Haddocks.

BSD-3-Clause licensed by Jonathan Fischoff
Maintained by [email protected]

This module is a drop in replacement for Data.Maybe. It generalizes the functions to any types that share the same "sum of products" view of Maybe.

To use the module for your type, enable GHC's DeriveGeneric extension and derive a Generic instance for your type.

import GHC.Generics

data Result a = Success a | Fail
   deriving (Show, Generic)

After which you can use the functions, like your type was Data.Maybe.Maybe

> fromMaybe 'a' Fail
'a'
> fromMaybe 'a' $ Success 'b'
'b'