Skip to content

Instantly share code, notes, and snippets.

@dtchepak
Created January 24, 2013 21:11
Show Gist options
  • Save dtchepak/4627796 to your computer and use it in GitHub Desktop.
Save dtchepak/4627796 to your computer and use it in GitHub Desktop.
import Control.Monad
import Data.Maybe
takeUntilBlank :: [Maybe a] -> [a]
--1)
--takeUntilBlank [] = []
--takeUntilBlank (Nothing:_) = []
--takeUntilBlank (x:xs) = maybe [] (\a -> a:takeUntilBlank xs) x
--
--2)
takeUntilBlank = map fromJust . takeUntil isNothing
takeUntil :: (a -> Bool) -> [a] -> [a]
--1)
-- takeUntil _ [] = []
-- takeUntil p (x:xs) = if p x then [] else x:takeUntil p xs
-- 2)
-- takeUntil p = foldr (\x acc -> if p x then [] else x:acc) []
-- 3)
takeUntil p = foldr (\x -> if p x then const [] else (x:)) []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment