Higher-order functions: Difference between revisions

no edit summary
No edit summary
Line 453:
$result = first('second');
 
==[[Ruby]]==
[[Category:Ruby]]
 
With a proc (procedure):
succ = proc{|x| x+1}
def to2(&f)
f[2]
end
to2(&succ) #=> 3
to2{|x| x+1} #=> 3
With a method:
def succ(n)
n+1
end
def to2(m)
m[2]
end
meth = method(:succ)
to2(meth) #=> 3
 
== [[Scala]]==
Anonymous user