Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

`on` runs a binary function by first running a unary function on each argument.

  Prelude> import Data.Function (on)
  Prelude Data.Function> :t on
  on :: (b -> b -> c) -> (a -> b) -> a -> a -> c
  Prelude Data.Function> f = undefined :: Int -> [Int]
  Prelude Data.Function> g = undefined :: Int -> [Int]
  Prelude Data.Function> :t ((&&) `on` (not . null . ($ x))) f g
  ((&&) `on` (not . null . ($ x))) f g :: Bool
Alternatively in Control.Arrow there's a 'fanout' operator &&&:

  Prelude Control.Arrow> f = undefined :: Int -> Bool
  Prelude Control.Arrow> g = undefined :: Int -> Bool
  Prelude Control.Arrow> :t uncurry (&&) . (f &&& g)
  uncurry (&&) . (f &&& g) :: Int -> Bool
Of course it's still probably simpler to just write it out in this case.





Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: