[Haskell-cafe] [Maybe Int] sans Nothings

michael rice nowgate at yahoo.com
Mon May 23 18:20:25 CEST 2011

What's the best way to end up with a list composed of only the Just values,no Nothings?
import Control.Monad.Stateimport Data.Maybe

type GeneratorState = State Int
tick :: GeneratorState (Maybe Int)tick = do n <- get          if ((n `mod` 7) == 0)            then              return Nothing            else do              put (n+1)              return (Just n)
{-*Main> evalState (sequence $ replicate 9 tick) 1[Just 1,Just 2,Just 3,Just 4,Just 5,Just 6,Nothing,Nothing,Nothing]-}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20110523/349cabdb/attachment.htm>

More information about the Haskell-Cafe mailing list