Skip to content

Instantly share code, notes, and snippets.

@fumieval
Created March 14, 2012 07:56
Show Gist options
  • Save fumieval/2034961 to your computer and use it in GitHub Desktop.
Save fumieval/2034961 to your computer and use it in GitHub Desktop.
collect :: (Functor m, Monad m) => Int -> [m [a]] -> m [a]
collect 0 _ = return []
collect _ [] = return []
collect 1 (x:_) = take 1 <$> x
collect n (x:xs) = x >>= \v -> (v ++) <$> collect (n - length v) xs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment