Jump to content

Higher-order functions: Difference between revisions

Coffeescript implementation
(Coffeescript implementation)
Line 407:
(println (modify-string append-hello "World!"))
</lang>
 
=={{header|CoffeeScript}}==
 
Passing an anonymous function to built-in map/reduce functions:
 
<lang coffeescript>double = [1,2,3].map (x) -> x*2</lang>
 
Using a function stored in a variable:
 
<lang coffeescript>fn = ->
return 8
 
sum = (a, b) -> a() + b()
 
sum(fn, fn) # => 16
</lang>
 
List comprehension with a function argument:
 
<lang coffeescript>bowl = ["Cheese", "Tomato"]
 
smash = (ingredient) ->
return "Smashed #{ingredient}"
 
contents = smash ingredient for ingredient in bowl</lang>
 
<pre>["Smashed Cheese", "Smashed Tomato"]</pre>
 
=={{header|Common Lisp}}==
Cookies help us deliver our services. By using our services, you agree to our use of cookies.