Skip to content

Instantly share code, notes, and snippets.

@oisdk oisdk/init.hs
Created Oct 24, 2019

Embed
What would you like to do?
init :: [a] -> [a]
init xs = foldr f b xs Nothing
where
b Nothing = error "init: empty list"
b _ = []
f x xs Nothing = xs (Just x)
f y xs (Just x) = x : xs (Just y)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.