module SpEither where import SP import EitherUtils(stripLeft,stripRight) import Spops(concatMapSP) mapFilterSP :: (t -> Maybe b) -> SP t b mapFilterSP t -> Maybe b f = SP t b m where m :: SP t b m = forall a b. (a -> SP a b) -> SP a b GetSP forall a b. (a -> b) -> a -> b $ \t x-> case t -> Maybe b f t x of Just b y -> forall a b. b -> SP a b -> SP a b PutSP b y SP t b m Maybe b Nothing -> SP t b m filterLeftSP :: SP (Either b b) b filterLeftSP = forall {t} {b}. (t -> Maybe b) -> SP t b mapFilterSP forall {a} {b}. Either a b -> Maybe a stripLeft filterRightSP :: SP (Either a1 b) b filterRightSP = forall {t} {b}. (t -> Maybe b) -> SP t b mapFilterSP forall {a1} {a2}. Either a1 a2 -> Maybe a2 stripRight filterJustSP :: SP (Maybe b) b filterJustSP = forall {t} {b}. (t -> Maybe b) -> SP t b mapFilterSP forall a. a -> a id splitSP :: SP (a, b) (Either a b) splitSP = forall {t} {b}. (t -> [b]) -> SP t b concatMapSP (\(a x, b y) -> [forall a b. a -> Either a b Left a x, forall a b. b -> Either a b Right b y]) toBothSP :: SP b (Either b b) toBothSP = forall {t} {b}. (t -> [b]) -> SP t b concatMapSP (\b x -> [forall a b. a -> Either a b Left b x, forall a b. b -> Either a b Right b x])