2 ms·
It can be written more concisely with fold. $ ghci Prelude> let getFromList ls pred = foldl (\x y -> if x `pred` y then x else y) (head ls) (tail ls) Pre
by it 15y ago
It can be written more concisely with fold.
$ ghci
Prelude> let getFromList ls pred = foldl (\x y -> if x `pred` y then x else y) (head ls) (tail ls)
Prelude> getFromList [1..10] (<)
1
Prelude> getFromList [1..10] (>)
10
- semisight 15y agoWhich can be done just as well in lisps. The whole point was to show it in a way that didn't confuse the Java devs. ;Clojure example (defn get-from-list [list pred] (reduce #(if (pred %1 %2) %1 %2) list))