Given a functor and given a specific way you want to unwrap its value , is there a predefined typeclass that you should implement to unwrap
it?
For example given a type: data X = X Int Int
where can i specialize the unwrapping
of a Maybe X
?
Lets say i have a a = Just (X 2 3)
and i want to unwrap
it the in a custom way:
(Just 2 3)-> 2^3
Nothing -> 0
But i also want to use the same method/interface to unwrap
another type like a Maybe (Int,Int)
like:
Just (x, y) -> x + y
Nothing -> 0
The question is more about organisation:
Is there a typeclass method where i can implement for unwrapping a Maybe X
,Maybe Y
, Either Z
, Either K
, etc.?
Or do i have to provide ungrouped (not a typeclass method instance) methods for each type that i want to unwrap from the functor?
What i mean is where do you place the code responsible for `extracting` the values from your functors? – Bercovici Adrian Nov 05 '18 at 08:38