Lists and Folding - vilinski/nemerle GitHub Wiki

Lists and Folding

  • Category: Lists, Tuples and Options
  • Description: This sample shows simple uses of 'Fold' to accumulate a result over a list
  • Code:
using Nemerle;
using Nemerle.Collections;
using System;
using System.Console;

def data = [("Cats", 4),
            ("Dogs", 5),
            ("Mice", 3),
            ("Elephants", 2)];
def count = data.Fold(0, ((_, nm), acc) => acc + nm);
WriteLine($"Total number of animals: $count")
  • Execution Result:
Total number of animals: 14

[Copyright ©](Terms of use, legal notice)