Hacker News new | ask | show | jobs
by embwbam 1061 days ago
Yes that’s exactly what the Maybe monad does! It would look like this in Haskell code

    doStuff :: Maybe X
    doStuff = do
      r1 <- cmd1
      r2 <- cmd2 r1
      …
      return rX
Which is syntactic sugar for:

    doStuff = cmd1 >>= cmd2 >>= …
1 comments

A sometimes important difference is that every process in the pipeline is spawned at the start, and may operate on partial input. A function returning Maybe needs to complete before we know whether it returns Just or Nothing, and we can't start the next function until we have the Just in hand, as that's the input to the function.