3 ms·
Is it standard practice in other languages / libraries to have the function argument first and the data argument second, in e.g. map and filter? In usual PHP f
by mappu 14y ago
Is it standard practice in other languages / libraries to have the function argument first and the data argument second, in e.g. map and filter?
In usual PHP fashion, array_map and array_filter take arguments in different orders. From all the jQuery i write it seems more natural to put the function argument last ($.get, $().bind, etc).
- rapala 14y agoI think the order of arguments comes from the use of partial application. In Haskell you can write: doubler :: Num a => [a] -> [a] doubler = map (2 *)
- walrus 14y agoPutting the data argument second is nice when combined with currying. For example: var bigNumbers = Udon.curry(Udon.filter)(function (number) { return number > 5; }); bigNumbers([3, 1, 4, 1, 5, 9]); // [9] bigNumbers([2, 7, 1, 8, 2, 8]); // [7, 8, 8]
- JackC 14y agoThe other reason things work this way in functional languages might be the way your nesting tends to work out. For example, it would be common in Clojure to write something like: (set-result-to (do-this-to (do-that-to (do-the-other-thing-to (map map-function some-input-data))))) If the order of arguments to map was reversed, your map function would be the only one messing up the right-to-left flow of your data. /so not a functional programmer