apply(fn, obj, ..., list)

Apply invokes fn, passing the first obj as the first argument, the second obj as the second argument, and so on for each object in obj ..., and passing the elements of list in order as the remaining arguments. Thus, fn is called with as many arguments as there are objs plus elements of list.

Apply is useful when some or all of the arguments to be passed to a function are in a list, without explicitly destructuring the list.


apply(append, [1,2,3], [[\a, \b], [5, 6]])
// [1, 2, 3, \a, \b, 5, 6]

function add_heads(xs)
  apply(`+`, map(head, xs))

add_heads([1:2, 3:4, 5:6])
// 9

Also see:


Core Module Index | Contents