-
Notifications
You must be signed in to change notification settings - Fork 89
Using Fold extended
NN--- edited this page Apr 18, 2012
·
3 revisions
- Category: Functions - Arrays, Lists, Seqs
- Description: .Fold applies a given function to the collection, threading an accumulator argument through and returning a single value.
- Code:
using System;
using System.Console;
using Nemerle;
using Nemerle.Collections;
def aoList2 = $[i * i, i in [1 .. 5]];
def sum = aoList2.Fold(0, _ + _);
def names = array["A", "man", "landed", "on", "the", "moon"];
def sentence = names.Fold("", (x, acc) => $"$acc $x");
WriteLine($"sum = $sum");
WriteLine($"sentence = $sentence")
- Execution Result:
sum = 55
sentence = A man landed on the moon
[Copyright ©](Terms of use, legal notice)