papa-0.5.0: src/Papa/Base/Data/Either.hs
{-# LANGUAGE CPP #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -Wall #-}
module Papa.Base.Data.Either (
module P,
lefts,
rights,
fromLeft,
fromRight,
) where
import Control.Applicative (Applicative (pure))
import Control.Category (Category (id, (.)))
import Control.Lens (Traversal, _Left, _Right)
import Data.Either as P (
Either (Left, Right),
either,
partitionEithers,
)
import Data.Traversable (Traversable (traverse))
{-# INLINE lefts #-}
lefts :: (Traversable f) => Traversal (f (Either a b)) (f (Either a' b)) a a'
lefts = traverse . _Left
{-# INLINE rights #-}
rights :: (Traversable f) => Traversal (f (Either a b)) (f (Either a b')) b b'
rights = traverse . _Right
{-# INLINE fromLeft #-}
fromLeft :: a -> Either a b -> a
fromLeft x = either id (pure x)
{-# INLINE fromRight #-}
fromRight :: b -> Either a b -> b
fromRight x = either (pure x) id