XDracam / unity-corelibrary

Collection of classes and extension methods that make life with Unity3D more comfortable
MIT License
15 stars 3 forks source link

`.Select` for tuples that takes n parameters #46

Open XDracam opened 5 years ago

XDracam commented 5 years ago

We would like a tupleList.Select((a, b) => a + b) method on every n-tuple which takes n arguments. This makes writing functional mappings a lot nicer when working with tuples, since lambda parameter lists do not support destructuring (yet?).

static IEnumerable<TRes> Select<TSource1, TSource2, TRes>(this IEnumerable<(TSource1, TSource2)> source, Func<TSource1, TSource2, TRes> fn) => 
    source.Select(t => fn(t.Item1, t.Item2));

Analogue implementations for tuples of size 3, since we would consider any larger tuples to be better represented by a custom struct.