These behave like overwriting > List.^find_method('split').wrap: { $^a.map: *.split($^b) } > List.^find_method('sin').wrap: *.map: *.sin; >
but they don't have to, since Aureliano started with "wrap" they can be actual wrappers: sub map-over-arg(\A) {my &nextone=nextcallee; A.map:{nextone $_}} List.^find_method('sin').wrap: &map-over-arg; List.^find_method('cos').wrap: &map-over-arg; my @nums = 0, π/2, 3 * π/2; say @nums.sin; *# (0 1 -1)* say @nums.cos; *# (1 6.123233995736766e-17 -1.8369701987210297e-16)* I'm not sure if that can be simplified to use "nextwith" instead of "nextcallee"–the "map" introduces a new scope which seems to require "nextcallee" The example with "split" is complicated by having 2 positionals only the first of which needs a map, not going to play with that at the moment, left as exercise to interested readers! -y On Mon, Oct 12, 2020 at 9:15 AM Aureliano Guedes <guedes.aureli...@gmail.com> wrote: > > > On Mon, Oct 12, 2020 at 10:03 AM Brian Duggan <bdug...@matatu.org> wrote: > >> On Saturday, October 10, William Michels via perl6-users wrote: >> > I can point to the (functional) R-programming language to show what >> happens >> > there. When manipulating "array-like" (i.e. vector) objects in R, you >> can >> > do nested function calls, or sequential (piped) function calls, and >> still >> > get the same data structure out at the end. So a 10-element input gives >> a >> > 10-element output. >> >> This seems pretty convenient and intuitive. At least, it is possible >> to mimic that behavior in Raku: >> >> List.^find_method('split').wrap: { $^a.map: *.split($^b) } >> List.^find_method('sin').wrap: *.map: *.sin; >> > This is like overwrite the function? > Might be better just implement a new function, I mean, a new verb as is > called in R. > > >> my @words = <a,b c,d>; >> my @nums = 0, π/2, 3 * π/2; >> >> say @words.split(','); >> say @nums.sin; >> >> gives us >> >> ((a b) (c d)) >> (0 1 -1) >> >> Brian >> > > > -- > Aureliano Guedes > skype: aureliano.guedes > contato: (11) 94292-6110 > whatsapp +5511942926110 >