Skip to content

Instantly share code, notes, and snippets.

@Cedev
Created August 7, 2015 00:26
Show Gist options
  • Save Cedev/c0cbd1ff7e70d0b7e53d to your computer and use it in GitHub Desktop.
Save Cedev/c0cbd1ff7e70d0b7e53d to your computer and use it in GitHub Desktop.
deleteLast :: (a -> Bool) -> [a] -> [a]
deleteLast delete = snd . go
where
go [] = (False, [])
go (x:xs) = (delete x || deleteLater, if not (delete x) || deleteLater then x:xs' else xs')
where
(deleteLater, xs') = go xs
filterLast p = deleteLast (not . p)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment