Next Tricks of the Wizards 205

Build Your Own map

        $n = reduce { $a + $b } 1, 4, 2, 8, 5, 7

(Yields the sum, 27)

        $n = reduce { $a * $b } 1, 4, 2, 8, 5, 7

(Yields the product, 2240)

        $n = reduce { $a > $b ? $a : $b } 1, 4, 2, 8, 5, 7

(Yields the max, 8)

        $n = reduce { [@$a, $b] } [], (1, 4, 2, 8, 5, 7)

(Yields a list, [1,4,2,8,5,7])


Next Copyright © 2003 M. J. Dominus