Is there any operator in Haskell that collapses a list of actions with (>>)?

I need an operator <?>

that could convert this

test arg1 >>
test arg2 >>
test arg3 >>
test arg4

      

to that

test <?> [ arg1
         , arg2
         , arg3
         , arg4
         ]

      

+3


source to share


1 answer


You can simply use for this: mapM_ :: Monad m => (a -> m b) -> [a] -> m ()

mapM_ test [arg1,arg2,arg3,arg4]

      



Or if you really want to write it infix:

test `mapM_` [ arg1
             , arg2
             , arg3
             , arg4
             ]

      

+7


source







All Articles