pikelang / Pike

Pike is a dynamic programming language with a syntax similar to Java and C. It is simple to learn, does not require long compilation passes and has powerful built-in data types allowing simple and really fast data manipulation.
http://pike.lysator.liu.se/
Other
194 stars 34 forks source link

Apply Method #46

Closed abdellahi-brahim closed 8 months ago

abdellahi-brahim commented 8 months ago

Pike already have map and filter. It would be nice to add an apply method. It's syntax would be something like this:

void apply(array data, function|string f, mixed ...args){
  foreach(data, mixed d){
    if(functionp(f))
      f(d, @args);
    else
      d[f](@args);
  }
}
eMBee commented 8 months ago

you can achieve this with the array[*] syntax.

essentially apply would be defined as:

array apply(array a; function f, mixed ... args){ 
    return f(a[*], @args); 
}

apply(a, doit, 5); would be equivalent to doit(a[*], 5);

abdellahi-brahim commented 8 months ago

Oooh, that is rly cool. Dynamic languages ftw ehehe