Skip to content

Instantly share code, notes, and snippets.

@ion1
Last active August 29, 2015 14:19
Show Gist options
  • Select an option

  • Save ion1/0672eea6e88188682106 to your computer and use it in GitHub Desktop.

Select an option

Save ion1/0672eea6e88188682106 to your computer and use it in GitHub Desktop.
From filter to partition
filter p zs = foldr (select p) [] zs where { select p x xs | p x = x:xs | otherwise = xs }
filter' p zs = foldr (select p) ([],()) zs where { select p x ~(xs,_) | p x = (x:xs, ()) | otherwise = (xs, ()) }
partition p zs = foldr (select p) ([],[]) zs where { select p x ~(xs,ys) | p x = (x:xs, ys) | otherwise = (xs, x:ys) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment