4 ms·
`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
by smegma2 6y ago
`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.
- codygman 6y agoAlso see this related discussion: https://www.reddit.com/r/programming/comments/ij0qzl/comment/g3dzohz https://www.reddit.com/r/programming/comments/ij0qzl/comment...