Après avoir vu cette vidéo, la réponse pourrait être « pas grand chose » ;)
Dans cette vidéo, on peut voir que Ruby se débrouille plutôt bien en ce qui concerne :
les high-order functions :
map=proc{|f,coll|# definition of a map functioncoll.map(&f)# using Enumerable#map...}inc=proc{|x|x+1}# proc that adds 1 to inputnums=[2,3,4]# data for us to map overmap.call(inc,nums)# returns [3, 4, 5]map.(inc,nums)# syntactic sugar to hide the `call`
le currying :
add=proc{|x,y|x+y}.curry# native curryingadd.(2,3)# returns 5inc=add.(1)# returns an add function with first argument pre-set as 1inc.(2)# returns 3map.(inc,[2,3,4])# returns [3, 4, 5]
la composition (de fonctions bien sûr) :
compose=proc{|x,y|proc{|*args|x.(y.(*args))}}inc=add.(1)# a inc functionadd2=add.(2)# a dec functionadd3=compose.(inc,add2)# returns a composition of inc and decadd3.(4)# returns 7, equivalent to `add2(inc(4))`# Personal bonus, or how to be more Haskel friendlyclassProc# Proc class monkey patched, MER IL ET FOUdef>>(f)returnproc{|*args|f.(self.(*args))}endendinc=add.(1)# an inc functionadd2=add.(2)# a dec functionadd3=inc>>add2# Haskel friendly composition ;Dadd3.(4)# returns 7, equivalent to `add2(inc(4))`
[^] # Re: Ruby <3
Posté par lepieru . En réponse à la dépêche Pendant ce temps, dans l’écosystème Ruby. Évalué à 3.
Après avoir vu cette vidéo, la réponse pourrait être « pas grand chose » ;)
Dans cette vidéo, on peut voir que Ruby se débrouille plutôt bien en ce qui concerne :