Join = reduce

I was driving today and I realized that join is just a form of reduce. Here’s some perl6:

sub join(Str $string, @array) {
   @array.reduce: { $^a ~ $string ~ $^b }
}

It works exactly as expected.

Posted Mon, Jan 26, 2009