RosettaCodeData/Task/Catamorphism/WDTE/catamorphism.wdte

14 lines
451 B
WDTE
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
let a => import 'arrays';
let s => import 'stream';
let str => import 'strings';
# Sum of [1, 10]:
let nums => [1; 2; 3; 4; 5; 6; 7; 8; 9; 10];
a.stream nums -> s.reduce 0 + -- io.writeln io.stdout;
# As an alternative to an array, a range stream can be used. Here's the product of [1, 11):
s.range 1 11 -> s.reduce 1 * -- io.writeln io.stdout;
# And here's a concatenation:
s.range 1 11 -> s.reduce '' (str.format '{}{}') -- io.writeln io.stdout;