Skip to content

Instantly share code, notes, and snippets.

@chris-martin
Created August 22, 2017 02:28
Show Gist options
  • Save chris-martin/c3886eca3bc4dc7e4509f8cb130f8f72 to your computer and use it in GitHub Desktop.
Save chris-martin/c3886eca3bc4dc7e4509f8cb130f8f72 to your computer and use it in GitHub Desktop.
data EqBy a = EqBy (a -> Bool) a
instance Eq (EqBy a) where
EqBy f _ == EqBy _ y = f y
eqBy :: (a -> a -> Bool) -> a -> EqBy a
eqBy f x = EqBy (f x) x
equalBy :: (a -> a -> Bool) -> [a] -> [a] -> Bool
equalBy f xs ys = fmap (eqBy f) xs == fmap (eqBy f) ys
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment