This project is read-only.
Tuple to list

Category:
Lists, Tuples and Options
Description: This sample converts a tuple to a list
Code:
let TupleToList() = 
let tupleToList t =
if Microsoft.FSharp.Reflection.FSharpType.IsTuple(t.GetType())
then Some (Microsoft.FSharp.Reflection.FSharpValue.GetTupleFields t |> Array.toList)
else None
let r = tupleToList (1,2,3,4)
match r with
| Some(x) -> x |> Seq.iter (fun n -> printfn "%A" n)
| None -> printfn "no element"

Execution Result:
1
2
3
4

Last edited Sep 14, 2011 at 3:47 AM by ttliu2000, version 1

Comments

No comments yet.