示例#1
0
        public void PartitionBooleanGrouping()
        {
            var(evens, odds) =
                Enumerable.Range(0, 10)
                .GroupBy(x => x % 2 == 0)
                .Partition((t, f) => Tuple.Create(t, f));

            Assert.That(evens, Is.EquivalentTo(new[] { 0, 2, 4, 6, 8 }));
            Assert.That(odds, Is.EquivalentTo(new[] { 1, 3, 5, 7, 9 }));
        }
示例#2
0
        public void PartitionNullableBooleanGrouping()
        {
            var xs = new int?[] { 1, 2, 3, null, 5, 6, 7, null, 9, 10 };

            var(lt5, gte5, nils) =
                xs.GroupBy(x => x != null ? x < 5 : (bool?)null)
                .Partition((t, f, n) => Tuple.Create(t, f, n));

            Assert.That(lt5, Is.EquivalentTo(new[] { 1, 2, 3 }));
            Assert.That(gte5, Is.EquivalentTo(new[] { 5, 6, 7, 9, 10 }));
            Assert.That(nils, Is.EquivalentTo(new int?[] { null, null }));
        }
示例#3
0
 public static Func <T, Unit> ToFunc <T>(this Action <T> action)
 => t =>
 {
     action(t);
     return(Unit.Create());
 };
示例#4
0
 ToValueTuple <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>(
     this Tuple <T1, T2, T3, T4, T5, T6, T7, Tuple <T8, T9, T10, T11, T12, T13, T14> > value)
 {
     return(CreateLong(value.Item1, value.Item2, value.Item3, value.Item4, value.Item5, value.Item6, value.Item7,
                       ValueTuple.Create(value.Rest.Item1, value.Rest.Item2, value.Rest.Item3, value.Rest.Item4, value.Rest.Item5, value.Rest.Item6, value.Rest.Item7)));
 }
示例#5
0
 ToValueTuple <T1, T2, T3, T4, T5, T6, T7>(
     this Tuple <T1, T2, T3, T4, T5, T6, T7> value)
 {
     return(ValueTuple.Create(value.Item1, value.Item2, value.Item3, value.Item4, value.Item5, value.Item6, value.Item7));
 }
示例#6
0
 ToValueTuple <T1, T2, T3, T4, T5>(
     this Tuple <T1, T2, T3, T4, T5> value)
 {
     return(ValueTuple.Create(value.Item1, value.Item2, value.Item3, value.Item4, value.Item5));
 }
示例#7
0
 ToValueTuple <T1, T2, T3>(
     this Tuple <T1, T2, T3> value)
 {
     return(ValueTuple.Create(value.Item1, value.Item2, value.Item3));
 }
示例#8
0
 ToValueTuple <T1, T2>(
     this Tuple <T1, T2> value)
 {
     return(ValueTuple.Create(value.Item1, value.Item2));
 }
 /// <summary>
 /// Make a properly nested <see cref="T:System.ValueTuple" /> from a properly nested <see cref="T:System.Tuple" /> with 4 elements.
 /// </summary>
 public static ValueTuple <T1, T2, T3, T4> ToValueTuple <T1, T2, T3, T4>(this Tuple <T1, T2, T3, T4> value)
 {
     return(ValueTuple.Create(value.Item1, value.Item2, value.Item3, value.Item4));
 }
示例#10
0
 public static Unit ForEach <T>(this List <T> @this, Action <T> action)
 {
     @this.Map(action.ToFunc());
     return(Unit.Create());
 }
 /// <summary>
 /// Make a properly nested <see cref="T:System.ValueTuple" /> from a properly nested <see cref="T:System.Tuple" /> with 21 elements.
 /// </summary>
 public static ValueTuple <T1, T2, T3, T4, T5, T6, T7, ValueTuple <T8, T9, T10, T11, T12, T13, T14, ValueTuple <T15, T16, T17, T18, T19, T20, T21> > > ToValueTuple <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21>(this Tuple <T1, T2, T3, T4, T5, T6, T7, Tuple <T8, T9, T10, T11, T12, T13, T14, Tuple <T15, T16, T17, T18, T19, T20, T21> > > value)
 {
     return(CreateLong(value.Item1, value.Item2, value.Item3, value.Item4, value.Item5, value.Item6, value.Item7, CreateLong(value.Rest.Item1, value.Rest.Item2, value.Rest.Item3, value.Rest.Item4, value.Rest.Item5, value.Rest.Item6, value.Rest.Item7, ValueTuple.Create(value.Rest.Rest.Item1, value.Rest.Rest.Item2, value.Rest.Rest.Item3, value.Rest.Rest.Item4, value.Rest.Rest.Item5, value.Rest.Rest.Item6, value.Rest.Rest.Item7))));
 }
 /// <summary>
 /// Make a properly nested <see cref="T:System.ValueTuple" /> from a properly nested <see cref="T:System.Tuple" /> with 10 elements.
 /// </summary>
 public static ValueTuple <T1, T2, T3, T4, T5, T6, T7, ValueTuple <T8, T9, T10> > ToValueTuple <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(this Tuple <T1, T2, T3, T4, T5, T6, T7, Tuple <T8, T9, T10> > value)
 {
     return(CreateLong(value.Item1, value.Item2, value.Item3, value.Item4, value.Item5, value.Item6, value.Item7, ValueTuple.Create(value.Rest.Item1, value.Rest.Item2, value.Rest.Item3)));
 }
 /// <summary>
 /// Make a properly nested <see cref="T:System.ValueTuple" /> from a properly nested <see cref="T:System.Tuple" /> with 6 elements.
 /// </summary>
 public static ValueTuple <T1, T2, T3, T4, T5, T6> ToValueTuple <T1, T2, T3, T4, T5, T6>(this Tuple <T1, T2, T3, T4, T5, T6> value)
 {
     return(ValueTuple.Create(value.Item1, value.Item2, value.Item3, value.Item4, value.Item5, value.Item6));
 }
示例#14
0
 public static Func <T1, T2, Unit> ToFunc <T1, T2>(this Action <T1, T2> action)
 => (T1 t1, T2 t2) =>
 {
     action(t1, t2);
     return(Unit.Create());
 };
示例#15
0
 ToValueTuple <T1>(
     this Tuple <T1> value)
 {
     return(ValueTuple.Create(value.Item1));
 }
示例#16
0
 public static Func <Unit> ToFunc(this Action action)
 => () =>
 {
     action();
     return(Unit.Create());
 };
 /// <summary>
 /// Make a properly nested <see cref="T:System.ValueTuple" /> from a properly nested <see cref="T:System.Tuple" /> with 1 element.
 /// </summary>
 public static ValueTuple <T1> ToValueTuple <T1>(this Tuple <T1> value)
 {
     return(ValueTuple.Create(value.Item1));
 }