Do you know the nicest way to make this work :
let toTableau2D (seqinit:seq<'a*'b*'c>) =
let myfst = fun (a,b,c) -> a
let myscd = fun (a,b,c) -> b
let mytrd = fun (a,b,c) -> c
let inputd = seqinit |> groupBy2 myfst myscd
there must be a better way than rewriting fst..
UPDATE
After pad advice, I rewrote packing the previous ‘a*’b into a single structure
My code now looks like
let toTableau (seqinit:seq<'a*'b>) =
let inputd = seqinit |> Seq.groupBy fst |> toMap
let keys = seqinit |> Seq.map fst |> Set.ofSeq |> List.ofSeq
...
Why don’t you just write it explicitly:
If you want to refer to
seqinitlater on, you always can reconstruct the triple or use the named pattern:EDIT:
Unless you use reflection, you cannot have
fstfunction for any kind of tuples. In your example, writing some utility functions and reusing them doesn’t hurt:If you want to make this work for arbitrary number of tuple elements, consider changing tuples to lists and employing pattern matching on lists.