Safe Haskell | None |
---|---|
Language | GHC2021 |
Synopsis
- data VEither (errs :: [Type]) a where
- toVary :: VEither errs a -> Vary (a : errs)
- fromVary :: Vary (a : errs) -> VEither errs a
- fromLeft :: forall err errs a. err :| errs => err -> VEither errs a
- fromRight :: forall a errs. a -> VEither errs a
- toEither :: VEither errs a -> Either (Vary errs) a
- fromEither :: Either (Vary errs) a -> VEither errs a
- veither :: (Vary errs -> c) -> (a -> c) -> VEither errs a -> c
- intoOnly :: forall a. VEither '[] a -> a
- onLeft :: forall err b errs a. (err -> b) -> (VEither errs a -> b) -> VEither (err : errs) a -> b
- onRight :: (a -> b) -> (VEither errs a -> b) -> VEither errs a -> b
- mapLeftOn :: forall x y xs ys a. Mappable x y xs ys => (x -> y) -> VEither xs a -> VEither ys a
- mapLeft :: (Vary xs -> Vary ys) -> VEither xs a -> VEither ys a
- mapRight :: (x -> y) -> VEither errs x -> VEither errs y
- morph :: forall ys xs a. Subset (a : xs) (a : ys) => VEither xs a -> VEither ys a
- morphed :: forall xs ys a res. Subset (a : xs) (a : ys) => (VEither ys a -> res) -> VEither xs a -> res
General Usage
This module is intended to be used qualified:
>>>
import Vary.VEither (VEither(VLeft, VRight))
>>>
import qualified Vary.VEither as VEither
And for many functions, it is useful or outright necessary to enable the following extensions:
>>>
:set -XGHC2021
>>>
:set -XDataKinds
Core type definition
data VEither (errs :: [Type]) a where Source #
pattern VLeft :: forall a errs. Vary errs -> VEither errs a | |
pattern VRight :: forall a errs. a -> VEither errs a |
Instances
Foldable (VEither errs) Source # | |
Defined in Vary.VEither fold :: Monoid m => VEither errs m -> m # foldMap :: Monoid m => (a -> m) -> VEither errs a -> m # foldMap' :: Monoid m => (a -> m) -> VEither errs a -> m # foldr :: (a -> b -> b) -> b -> VEither errs a -> b # foldr' :: (a -> b -> b) -> b -> VEither errs a -> b # foldl :: (b -> a -> b) -> b -> VEither errs a -> b # foldl' :: (b -> a -> b) -> b -> VEither errs a -> b # foldr1 :: (a -> a -> a) -> VEither errs a -> a # foldl1 :: (a -> a -> a) -> VEither errs a -> a # toList :: VEither errs a -> [a] # null :: VEither errs a -> Bool # length :: VEither errs a -> Int # elem :: Eq a => a -> VEither errs a -> Bool # maximum :: Ord a => VEither errs a -> a # minimum :: Ord a => VEither errs a -> a # | |
Traversable (VEither errs) Source # | |
Defined in Vary.VEither | |
Applicative (VEither errs) Source # | |
Defined in Vary.VEither | |
Functor (VEither errs) Source # | |
Monad (VEither errs) Source # | |
Semigroup (VEither errs a) Source # | |
Generic (VEither errs a) Source # | |
(Show a, Show (Vary errs)) => Show (VEither errs a) Source # | |
(NFData a, NFData (Vary errs)) => NFData (VEither errs a) Source # | |
Defined in Vary.VEither | |
(Eq a, Eq (Vary errs)) => Eq (VEither errs a) Source # | |
(Ord a, Ord (Vary errs)) => Ord (VEither errs a) Source # | |
Defined in Vary.VEither compare :: VEither errs a -> VEither errs a -> Ordering # (<) :: VEither errs a -> VEither errs a -> Bool # (<=) :: VEither errs a -> VEither errs a -> Bool # (>) :: VEither errs a -> VEither errs a -> Bool # (>=) :: VEither errs a -> VEither errs a -> Bool # | |
type Rep (VEither errs a) Source # | |
Defined in Vary.VEither type Rep (VEither errs a) = D1 ('MetaData "VEither" "Vary.VEither" "vary" 'False) (C1 ('MetaCons "VLeft" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Vary errs))) :+: C1 ('MetaCons "VRight" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a))) |
Conversion
toVary :: VEither errs a -> Vary (a : errs) Source #
Turns the VEither
into a normal Vary, no longer considering the a
a 'preferred' value.
fromLeft :: forall err errs a. err :| errs => err -> VEither errs a Source #
Shorthand to construct a VEither
from a single error value.
Instead of:
>>>
(VLeft (Vary.from @Bool True)) :: VEither '[Bool] String
VLeft (Vary.from @Bool True)
You can just write:
>>>
VEither.fromLeft @Bool True :: VEither '[Bool] String
VLeft (Vary.from @Bool True)
case analysis ("pattern matching"):
Besides the VLeft
and VRight
patterns,
VEither
supports a bunch of handy combinator functions,
similar to Vary.on
and co.
onLeft :: forall err b errs a. (err -> b) -> (VEither errs a -> b) -> VEither (err : errs) a -> b Source #
Transforming
mapLeftOn :: forall x y xs ys a. Mappable x y xs ys => (x -> y) -> VEither xs a -> VEither ys a Source #