module Data.Functor.MaybeLike where
import Data.Functor.Identity
class MaybeLike f where
likeMaybe :: f a -> Maybe a
instance MaybeLike Identity where
likeMaybe :: Identity a -> Maybe a
likeMaybe = a -> Maybe a
forall a. a -> Maybe a
Just (a -> Maybe a) -> (Identity a -> a) -> Identity a -> Maybe a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Identity a -> a
forall a. Identity a -> a
runIdentity
instance MaybeLike Maybe where
likeMaybe :: Maybe a -> Maybe a
likeMaybe = Maybe a -> Maybe a
forall a. a -> a
id
instance MaybeLike (Either a) where
likeMaybe :: Either a a -> Maybe a
likeMaybe (Left _) = Maybe a
forall a. Maybe a
Nothing
likeMaybe (Right y :: a
y) = a -> Maybe a
forall a. a -> Maybe a
Just a
y