on
combinatorλ> let outer f x y = fmap (\a -> fmap (f a) y) x λ> let self f x = f x x -- Like ⍨ from APL λ> let on = self . outer
on
is identical to the combinator provided by Data.Function
.
λ> sortBy (compare `on` snd) [(1,"c"),(3,"a"),(4,"d")] [(3,"a"),(1,"c"),(4,"d")]
The same functionality in APL:
on ← { (⍵⍵ ⍺) ⍺⍺ (⍵⍵ ⍵) } ⍝ Proposed Over (⍥) operator 'ra' , on ⌽ 'yar' array