Trying to understand the pattern used to deal with possible failures inside IO
. If its just one case
s like below, its probably acceptable, but if the nesting goes on for a bunch of nested IO (Either String Int)
s is there a common pattern to handle such types. For instance, if b
in functionDoSomething
is again a (Either a b)
and fetching value on success and doing something with it again will be another such case
. Is there a higher order function that I can use? I'm not comfortable with monad transformers yet, not sure if they can be used to deal with this specific monad stack. If they can be used here, is there a way to do it without using them.
import Control.Monad
functionCreate :: Int -> IO (Either String Int)
functionDoSomething :: Int -> IO b
functionUse :: IO ()
functionUse = do
created <- functionCreate 10
case created of
(Right v) -> void $ functionDoSomething v
_ -> return ()