This task is for iterations and iterations like libraries.
Using the proxy library.
import Control.Proxy runProxy $ fromListS [1..10] >-> <processing> >-> printD >-> <more> processing>
Where <processing> are the addition calculations you have to do.
Related questions: lazy version of mapM , Is Haskell mapM not lazy?
For instance:
> labeledPrint label x = putStrLn $ label ++ show x > runProxy $ fromListS [1..4] >-> printD >-> mapD (*2) >-> useD (labeledPrint "Second printer: ") 1 Second printer: 2 2 Second printer: 4 3 Second printer: 6 4 Second printer: 8
If you cancel the order of use of the application and use <-< instead of >-> , it will look like a normal application.
runProxy $ useD (labeledPrint "Second printer: ") <-< mapD (*2) <-< printD <-< fromListS [1..4]
source share