mapM return = cat mapM (f >=> g) = mapM f >-> mapM g
Streams.mapM (f >=> g) === Streams.mapM f >=> Streams.mapM g Streams.mapM return === Streams.makeInputStream . Streams.read
>>> S.print $ S.mapM readIORef $ S.chain (\ior -> modifyIORef ior (*100)) $ S.mapM newIORef $ each [1..6] 100 200 300 400 500 600See also chain for a variant of this which ignores the return value of the function and just uses the side effects.
mapM f = sequence . map fApply a monadic function to each element of the stream and replace it with the output of the resulting action.
>>> drain $ Stream.mapM putStr $ Stream.fromList ["a", "b", "c"] abc >>> :{ drain $ Stream.replicateM 10 (return 1) & (fromSerial . Stream.mapM (x -> threadDelay 1000000 >> print x)) :} 1 ... 1 > drain $ Stream.replicateM 10 (return 1) & (fromAsync . Stream.mapM (x -> threadDelay 1000000 >> print x))Concurrent (do not use with fromParallel on infinite streams)