!{x!      (c) Dennis Gosnell, 2016BSD-style (see LICENSE file)cdep.illabout@gmail.com experimentalPOSIXSafew from-sumA monadic version of  .   leftAction === ! leftAction " (fromEitherM (\s -> [length s]) $ Right 5[5]7fromEitherM (\s -> [length s]) $ Left ("foo" :: String)[3]from-sumA #ed version of .*fromEitherOrM (Right 5) $ \s -> [length s][5],This can be nice to use as an error handler.FfromEitherOrM (Right 5) $ \s -> putStrLn ("error: " ++ s) >> undefined5IfromEitherOrM (Left "foo") $ \s -> putStrLn ("error: " ++ s) >> undefined error: foo...from-sum Similar to , but only run the monadic  leftAction if the $ argument is %. Otherwise, return " &.   leftAction === ! leftAction (' ( " &) ;fromEitherM_ (\err -> putStrLn err >> pure "bye") $ Right 5""MfromEitherM_ (\err -> putStrLn err >> pure "bye") $ Left "there was an error"there was an error"bye"WThis can be convenient when you want to run some sort of logging function whenever an $ is %+. If you imagine the logging function is b -> ) '()', then the effective type of  becomes  :: (e -> ) '()') -> $ e a -> ) '()', because '()' has a * instance, and ) , has an + instance.1fromEitherM_ putStrLn $ Left "there was an error"there was an errorfrom-sumA #ed version of .from-sumA monadic version of .   nothingAction === , nothingAction " fromMaybeM [] $ Just 5[5]fromMaybeM [] Nothing[]from-sumA #ed version of .fromMaybeOrM (Just 5) [][5],This can be nice to use as an error handler.CfromMaybeOrM (Just 5) $ putStrLn "some error occurred" >> undefined5DfromMaybeOrM (Nothing) $ putStrLn "some error occurred" >> undefinedsome error occurred...from-sum Similar to , but only run the monadic  nothingAction if the - argument is .. Otherwise, return " &.   nothingAction === , nothingAction (' ( " &) 5fromMaybeM_ (putStrLn "hello" >> pure "bye") $ Just 5""4fromMaybeM_ (putStrLn "hello" >> pure "bye") Nothinghello"bye"VThis can be convenient when you want to run some sort of logging function whenever a - is .+. If you imagine the logging function is ) '()', then the effective type of  becomes  :: ) '()' -> - a -> ) '()', because '()' has a * instance, and ) , has an + instance.&fromMaybeM_ (putStrLn "hello") Nothinghellofrom-sumA #ed version of . from-sum Similar to  but the $" argument is also a monadic value.3fromEitherMM (\s -> [length s]) [Right 5, Right 10][5,10]CfromEitherMM (\s -> [length s]) [Left ("foo" :: String), Right 100][3,100]NOTE: I don't particularly like the name of this function. If you have a suggestion for a better name, please submit a PR or issue. from-sumA #ed version of  . from-sum Similar to  but the -" argument is also a monadic value.fromMaybeMM [] [Just 6, Just 5][6,5](fromMaybeMM [] [Just 6, Nothing, Just 7][6,7]NOTE: I don't particularly like the name of this function. If you have a suggestion for a better name, please submit a PR or issue. from-sumA #ed version of  . from-sum Similar to .fromEither show $ Left 5"5"fromEither show $ Right "hello""hello"from-sumA #ed version of  .from-sumA #ed version of .from-sum Collapse an $ a a to an a. Defined as   /..Note: Other libraries export this function as  fromEither , but our  # function is slightly more general.collapseEither (Right 3)3collapseEither (Left "hello")"hello"from-sum Similar to  , but for 0.*collapseExceptT (ExceptT $ pure (Right 3))3/collapseExceptT (ExceptT $ pure (Left "hello"))"hello"from-sum Collapse an 0A where the error returns the same type as the whole computation.2let exceptTOne = pure 3 :: ExceptT (IO Int) IO Int'collapseErrExceptT exceptTOne :: IO Int3This is helpful when writing short-circuiting computations where you throw errors that match the type of the underlying computation.:{ &let go :: Int -> ExceptT (IO ()) IO () go x = do bar <- if x < 10 then pure "hello" else8 throwE (putStrLn "Error occurred, x too big!")' lift $ putStrLn $ bar ++ " world":}$collapseErrExceptT (go 100) :: IO ()Error occurred, x too big!"collapseErrExceptT (go 3) :: IO () hello world'In this example, the error type in the 0 is ) (). This allows us to easily short-circuit the remaining computations. In this example, the remaining computation is just printing bar 1 " world".from-sum Convert a - to an $.If the - is 2, then return the value in 3.maybeToEither 3 $ Just "hello" Right "hello"If the - is ., then use the given e as %.maybeToEither 3 NothingLeft 3from-sumA #ed version of . maybeToEitherOr (Just "hello") 3 Right "hello"maybeToEitherOr Nothing 3Left 3from-sum Convert an $ to a -.A 3 value becomes 2.eitherToMaybe $ Right 3Just 3A % value becomes ..eitherToMaybe $ Left "bye"Nothingfrom-sumLift an $ into an 0.This is the same as *, but the return type is specialized for 0.:liftEitherExceptT (Right 3) :: ExceptT String Identity IntExceptT (Identity (Right 3))Note that if you want to lift m ($ e a) to 0 e m a , just use 0:@action = Identity (Left "error") :: Identity (Either String Int)-ExceptT action :: ExceptT String Identity Int!ExceptT (Identity (Left "error"))from-sumLift an $ to an 02 with a handler for transforming the error value. If the input $ is 3", then just return it like normal:.let rightEither = Right () :: Either String ()MfromEitherExceptT (\str -> length str) rightEither :: ExceptT Int Identity ()ExceptT (Identity (Right ())) If the input $ is %%, then pass the value to the handler:1let leftEither = Left "hello" :: Either String ()LfromEitherExceptT (\str -> length str) leftEither :: ExceptT Int Identity ()ExceptT (Identity (Left 5))from-sum Just like  , but the arguments are flipped.from-sum Similar to  but the $ value is lifted in a 4.Ilet identityLeft = Identity (Left "hello") :: Identity (Either String ())OfromEitherMExceptT (\str -> length str) identityLeft :: ExceptT Int Identity ()ExceptT (Identity (Left 5))This is similar to ,, but the second argument is the unwrapped 0 computation.from-sum Just like  , but the arguments are flipped.from-sumLift a - to an 0- with a default value for the case when the - is ..If the - is 2), then just return the value like normal:%let justVal = Just True :: Maybe Bool7fromMaybeExceptT 5 justVal :: ExceptT Int Identity BoolExceptT (Identity (Right True))If the - is .0, then use the default value as the error value:&let nothingVal = Nothing :: Maybe Bool:fromMaybeExceptT 5 nothingVal :: ExceptT Int Identity BoolExceptT (Identity (Left 5))from-sum Just like  but with the arguments flipped.from-sum Similar to  except the - value is lifted in a 4.?let identityNothing = Identity Nothing :: Identity (Maybe Bool)@fromMaybeMExceptT 5 identityNothing :: ExceptT Int Identity BoolExceptT (Identity (Left 5))from-sum Just like  but with the arguments flipped.from-sum Similar to guard , but for 0.If the 5 is 6, then do nothing.@guardExceptT True "error occurred" :: ExceptT String Identity ()ExceptT (Identity (Right ()))If the 5 is 7, then return the error case:AguardExceptT False "error occurred" :: ExceptT String Identity ()*ExceptT (Identity (Left "error occurred")) from-sum Just like  (and similar to guardM&), except the boolean is lifted in a 4.MguardMExceptT (Identity False) "error occurred" :: ExceptT String Identity ()*ExceptT (Identity (Left "error occurred"))!  !  8      !"#$%&'()*+,+-).)/+0+1+2345+6+789:9;+<=>+?9@)A+B34C34D34EF'from-sum-0.2.3.0-FcdF6ca0ebTBdqflE0LAW3Control.FromSumControl.Monad.Except liftEitherControl.Monad.Trans.Except withExceptTbase Data.Maybe fromMaybe fromEitherM fromEitherOrM fromEitherM_fromEitherOrM_ fromMaybeM fromMaybeOrM fromMaybeM_ fromMaybeOrM_ fromEitherMMfromEitherOrMM fromMaybeMM fromMaybeOrMM fromEither fromEitherOr fromMaybeOrcollapseEithercollapseExceptTcollapseErrExceptT maybeToEithermaybeToEitherOr eitherToMaybeliftEitherExceptTfromEitherExceptTfromEitherOrExceptTfromEitherMExceptTfromEitherOrMExceptTfromMaybeExceptTfromMaybeOrExceptTfromMaybeMExceptTfromMaybeOrMExceptT guardExceptT guardMExceptT Data.EithereitherGHC.BasepureflipEitherLeftmemptyconst$ghc-prim GHC.TypesIOMonoid Applicativemaybe GHC.MaybeMaybeNothingidtransformers-0.5.5.0ExceptT++JustRightMonadBoolTrueFalse