Tuple to list - vilinski/nemerle GitHub Wiki

Tuple to list

  • Category: Lists, Tuples and Options
  • Description: This sample converts a tuple to a list
  • Code:
using System;
using System.Console;
using Nemerle;
using Nemerle.Collections;

def tupleToList[T](t : T)
{
  def type = typeof(T);
  if (type.FullName.StartsWith("Nemerle.Builtins.Tuple"))
  {
    Some(type.GetFields().MapToList(_.GetValue(t)))
  } else None()
}

match (tupleToList(1, 2, 3, 4))
{
  | Some(x) => WriteLine(x)
  | _       => WriteLine("no element")
}
  • Execution Result:
[1, 2, 3, 4]

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