4 ms·
I find higher-order function to be really beautiful with CoffeeScript: partial = (fn, a...) -> (b...) -> fn.apply this, [a..., b...] compose = (fns...) ->
by nadaviv 14y ago
I find higher-order function to be really beautiful with CoffeeScript:
partial = (fn, a...) -> (b...) -> fn.apply this, [a..., b...]
compose = (fns...) -> (a) -> a = fn a for fn in fns; a
splat = (fn) -> (arr) -> arr.map fn
get = (attr) -> (obj) -> obj[attr]
maybe = (fn) -> (args...) ->
return unless args.length
return arg for arg in args when not arg?
fn.apply this, args
- wonderzombie 14y agoBeauty is, of course, subjective, but the use of 'this' stands out to me as unusual for these particular patterns. Call it a slightly leaky abstraction, I suppose. That said, at least the function declaration syntax looks a lot like Haskell's type signatures. So maybe they're doing something right. :)