Created
May 15, 2013 14:11
-
-
Save michaelfeathers/5584260 to your computer and use it in GitHub Desktop.
Create a zip-esque running annotation for a list based upon a predicate.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
saddle :: (a->Bool) -> [a] -> [(a,a)] | |
saddle f [] = [] | |
saddle f (x:xs) = saddle' f x xs | |
saddle' :: (a->Bool) -> a -> [a] -> [(a,a)] | |
saddle' f initial [] = [] | |
saddle' f initial (x:xs) = (x, sideValue x) : saddle' f (sideValue x) xs | |
where sideValue x = if f x then x else initial |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment