-
Notifications
You must be signed in to change notification settings - Fork 89
Tuple to list
NN--- edited this page Apr 18, 2012
·
7 revisions
- 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)