From 2cc42b424ac44417d8b09fa61b270426d9ee95b0 Mon Sep 17 00:00:00 2001 From: Paul Louth Date: Sun, 12 Jan 2020 13:44:06 +0000 Subject: [PATCH] Collection ToString, ToFullString, ToFullArrayString --- LanguageExt.Core/DataTypes/Arr/Arr.cs | 24 ++++ .../DataTypes/HashMap/HashMap.Eq.cs | 24 ++++ LanguageExt.Core/DataTypes/HashMap/HashMap.cs | 24 ++++ .../DataTypes/HashSet/HashSet.Eq.cs | 24 ++++ LanguageExt.Core/DataTypes/HashSet/HashSet.cs | 24 ++++ .../DataTypes/List/Lst.Predicate.cs | 24 ++++ .../DataTypes/List/Lst.Predicate2.cs | 24 ++++ LanguageExt.Core/DataTypes/List/Lst.cs | 24 ++++ LanguageExt.Core/DataTypes/Map/Map.Ord.cs | 25 ++++ LanguageExt.Core/DataTypes/Map/Map.cs | 24 ++++ LanguageExt.Core/DataTypes/Seq/Seq.cs | 26 ++++ LanguageExt.Core/DataTypes/Set/Set.cs | 22 +++- LanguageExt.Core/DataTypes/Stack/Stck.cs | 24 ++++ LanguageExt.Core/Utility/CollectionFormat.cs | 43 +++++-- LanguageExt.Tests/CollectionToStringTests.cs | 112 ++++++++++++++++++ LanguageExt.Tests/ListTests.cs | 4 +- 16 files changed, 456 insertions(+), 16 deletions(-) create mode 100644 LanguageExt.Tests/CollectionToStringTests.cs diff --git a/LanguageExt.Core/DataTypes/Arr/Arr.cs b/LanguageExt.Core/DataTypes/Arr/Arr.cs index 697df10c5..8cf6d5c17 100644 --- a/LanguageExt.Core/DataTypes/Arr/Arr.cs +++ b/LanguageExt.Core/DataTypes/Arr/Arr.cs @@ -455,6 +455,30 @@ public IEnumerable AsEnumerable() => public Seq ToSeq() => Seq(this); + /// + /// Format the collection as `[a, b, c, ...]` + /// The elipsis is used for collections over 50 items + /// To get a formatted string with all the items, use `ToFullString` + /// or `ToFullArrayString`. + /// + [Pure] + public override string ToString() => + CollectionFormat.ToShortArrayString(this, Count); + + /// + /// Format the collection as `a, b, c, ...` + /// + [Pure] + public string ToFullString(string separator = ", ") => + CollectionFormat.ToFullString(this); + + /// + /// Format the collection as `[a, b, c, ...]` + /// + [Pure] + public string ToFullArrayString(string separator = ", ") => + CollectionFormat.ToFullArrayString(this); + [Pure] public IEnumerable Skip(int amount) => Value.Skip(amount); diff --git a/LanguageExt.Core/DataTypes/HashMap/HashMap.Eq.cs b/LanguageExt.Core/DataTypes/HashMap/HashMap.Eq.cs index 107f8acd0..54da37ce6 100644 --- a/LanguageExt.Core/DataTypes/HashMap/HashMap.Eq.cs +++ b/LanguageExt.Core/DataTypes/HashMap/HashMap.Eq.cs @@ -621,6 +621,30 @@ IEnumerator IEnumerable.GetEnumerator() => public Seq<(K Key, V Value)> ToSeq() => Seq(Value.AsEnumerable()); + /// + /// Format the collection as `[(key: value), (key: value), (key: value), ...]` + /// The elipsis is used for collections over 50 items + /// To get a formatted string with all the items, use `ToFullString` + /// or `ToFullArrayString`. + /// + [Pure] + public override string ToString() => + CollectionFormat.ToShortArrayString(AsEnumerable().Map(kv => $"({kv.Key}: {kv.Value})"), Count); + + /// + /// Format the collection as `(key: value), (key: value), (key: value), ...` + /// + [Pure] + public string ToFullString(string separator = ", ") => + CollectionFormat.ToFullString(AsEnumerable().Map(kv => $"({kv.Key}: {kv.Value})")); + + /// + /// Format the collection as `[(key: value), (key: value), (key: value), ...]` + /// + [Pure] + public string ToFullArrayString(string separator = ", ") => + CollectionFormat.ToFullArrayString(AsEnumerable().Map(kv => $"({kv.Key}: {kv.Value})")); + [Pure] public IEnumerable<(K Key, V Value)> AsEnumerable() => Value.AsEnumerable(); diff --git a/LanguageExt.Core/DataTypes/HashMap/HashMap.cs b/LanguageExt.Core/DataTypes/HashMap/HashMap.cs index 79db54f16..e5585a580 100644 --- a/LanguageExt.Core/DataTypes/HashMap/HashMap.cs +++ b/LanguageExt.Core/DataTypes/HashMap/HashMap.cs @@ -646,6 +646,30 @@ IEnumerator IEnumerable.GetEnumerator() => public Seq<(K Key, V Value)> ToSeq() => Seq(AsEnumerable()); + /// + /// Format the collection as `[(key: value), (key: value), (key: value), ...]` + /// The elipsis is used for collections over 50 items + /// To get a formatted string with all the items, use `ToFullString` + /// or `ToFullArrayString`. + /// + [Pure] + public override string ToString() => + CollectionFormat.ToShortArrayString(AsEnumerable().Map(kv => $"({kv.Key}: {kv.Value})"), Count); + + /// + /// Format the collection as `(key: value), (key: value), (key: value), ...` + /// + [Pure] + public string ToFullString(string separator = ", ") => + CollectionFormat.ToFullString(AsEnumerable().Map(kv => $"({kv.Key}: {kv.Value})")); + + /// + /// Format the collection as `[(key: value), (key: value), (key: value), ...]` + /// + [Pure] + public string ToFullArrayString(string separator = ", ") => + CollectionFormat.ToFullArrayString(AsEnumerable().Map(kv => $"({kv.Key}: {kv.Value})")); + [Pure] public IEnumerable<(K Key, V Value)> AsEnumerable() => Value; diff --git a/LanguageExt.Core/DataTypes/HashSet/HashSet.Eq.cs b/LanguageExt.Core/DataTypes/HashSet/HashSet.Eq.cs index c605e1977..5aba159cc 100644 --- a/LanguageExt.Core/DataTypes/HashSet/HashSet.Eq.cs +++ b/LanguageExt.Core/DataTypes/HashSet/HashSet.Eq.cs @@ -392,6 +392,30 @@ IEnumerator IEnumerable.GetEnumerator() => public Seq ToSeq() => Prelude.Seq(this); + /// + /// Format the collection as `[a, b, c, ...]` + /// The elipsis is used for collections over 50 items + /// To get a formatted string with all the items, use `ToFullString` + /// or `ToFullArrayString`. + /// + [Pure] + public override string ToString() => + CollectionFormat.ToShortArrayString(this, Count); + + /// + /// Format the collection as `a, b, c, ...` + /// + [Pure] + public string ToFullString(string separator = ", ") => + CollectionFormat.ToFullString(this); + + /// + /// Format the collection as `[a, b, c, ...]` + /// + [Pure] + public string ToFullArrayString(string separator = ", ") => + CollectionFormat.ToFullArrayString(this); + [Pure] public IEnumerable AsEnumerable() => this; diff --git a/LanguageExt.Core/DataTypes/HashSet/HashSet.cs b/LanguageExt.Core/DataTypes/HashSet/HashSet.cs index bce955840..dcc261030 100644 --- a/LanguageExt.Core/DataTypes/HashSet/HashSet.cs +++ b/LanguageExt.Core/DataTypes/HashSet/HashSet.cs @@ -381,6 +381,30 @@ IEnumerator IEnumerable.GetEnumerator() => public Seq ToSeq() => Prelude.Seq(this); + /// + /// Format the collection as `[a, b, c, ...]` + /// The elipsis is used for collections over 50 items + /// To get a formatted string with all the items, use `ToFullString` + /// or `ToFullArrayString`. + /// + [Pure] + public override string ToString() => + CollectionFormat.ToShortArrayString(this, Count); + + /// + /// Format the collection as `a, b, c, ...` + /// + [Pure] + public string ToFullString(string separator = ", ") => + CollectionFormat.ToFullString(this); + + /// + /// Format the collection as `[a, b, c, ...]` + /// + [Pure] + public string ToFullArrayString(string separator = ", ") => + CollectionFormat.ToFullArrayString(this); + [Pure] public IEnumerable AsEnumerable() => this; diff --git a/LanguageExt.Core/DataTypes/List/Lst.Predicate.cs b/LanguageExt.Core/DataTypes/List/Lst.Predicate.cs index 12356d171..1860f2504 100644 --- a/LanguageExt.Core/DataTypes/List/Lst.Predicate.cs +++ b/LanguageExt.Core/DataTypes/List/Lst.Predicate.cs @@ -245,6 +245,30 @@ IEnumerator IEnumerable.GetEnumerator() => public Seq ToSeq() => Seq(this); + /// + /// Format the collection as `[a, b, c, ...]` + /// The elipsis is used for collections over 50 items + /// To get a formatted string with all the items, use `ToFullString` + /// or `ToFullArrayString`. + /// + [Pure] + public override string ToString() => + CollectionFormat.ToShortArrayString(this, Count); + + /// + /// Format the collection as `a, b, c, ...` + /// + [Pure] + public string ToFullString(string separator = ", ") => + CollectionFormat.ToFullString(this); + + /// + /// Format the collection as `[a, b, c, ...]` + /// + [Pure] + public string ToFullArrayString(string separator = ", ") => + CollectionFormat.ToFullArrayString(this); + [Pure] public IEnumerable AsEnumerable() => this; diff --git a/LanguageExt.Core/DataTypes/List/Lst.Predicate2.cs b/LanguageExt.Core/DataTypes/List/Lst.Predicate2.cs index 159d0ef8d..d77e59180 100644 --- a/LanguageExt.Core/DataTypes/List/Lst.Predicate2.cs +++ b/LanguageExt.Core/DataTypes/List/Lst.Predicate2.cs @@ -177,6 +177,30 @@ public IEnumerator GetEnumerator() => public Seq ToSeq() => Seq(this); + /// + /// Format the collection as `[a, b, c, ...]` + /// The elipsis is used for collections over 50 items + /// To get a formatted string with all the items, use `ToFullString` + /// or `ToFullArrayString`. + /// + [Pure] + public override string ToString() => + CollectionFormat.ToShortArrayString(this, Count); + + /// + /// Format the collection as `a, b, c, ...` + /// + [Pure] + public string ToFullString(string separator = ", ") => + CollectionFormat.ToFullString(this); + + /// + /// Format the collection as `[a, b, c, ...]` + /// + [Pure] + public string ToFullArrayString(string separator = ", ") => + CollectionFormat.ToFullArrayString(this); + [Pure] public IEnumerable AsEnumerable() => this; diff --git a/LanguageExt.Core/DataTypes/List/Lst.cs b/LanguageExt.Core/DataTypes/List/Lst.cs index 310e4ac36..89882f10a 100644 --- a/LanguageExt.Core/DataTypes/List/Lst.cs +++ b/LanguageExt.Core/DataTypes/List/Lst.cs @@ -302,6 +302,30 @@ IEnumerator IEnumerable.GetEnumerator() => public Seq ToSeq() => Seq(this); + /// + /// Format the collection as `[a, b, c, ...]` + /// The elipsis is used for collections over 50 items + /// To get a formatted string with all the items, use `ToFullString` + /// or `ToFullArrayString`. + /// + [Pure] + public override string ToString() => + CollectionFormat.ToShortArrayString(this, Count); + + /// + /// Format the collection as `a, b, c, ...` + /// + [Pure] + public string ToFullString(string separator = ", ") => + CollectionFormat.ToFullString(this); + + /// + /// Format the collection as `[a, b, c, ...]` + /// + [Pure] + public string ToFullArrayString(string separator = ", ") => + CollectionFormat.ToFullArrayString(this); + [Pure] public IEnumerable AsEnumerable() => this; diff --git a/LanguageExt.Core/DataTypes/Map/Map.Ord.cs b/LanguageExt.Core/DataTypes/Map/Map.Ord.cs index 68d7f4590..9984e4fb1 100644 --- a/LanguageExt.Core/DataTypes/Map/Map.Ord.cs +++ b/LanguageExt.Core/DataTypes/Map/Map.Ord.cs @@ -623,6 +623,31 @@ IEnumerator IEnumerable.GetEnumerator() => public Seq<(K Key, V Value)> ToSeq() => Seq(this); + /// + /// Format the collection as `[(key: value), (key: value), (key: value), ...]` + /// The elipsis is used for collections over 50 items + /// To get a formatted string with all the items, use `ToFullString` + /// or `ToFullArrayString`. + /// + [Pure] + public override string ToString() => + CollectionFormat.ToShortArrayString(ValueTuples.Map(kv => $"({kv.Key}: {kv.Value})"), Count); + + /// + /// Format the collection as `(key: value), (key: value), (key: value), ...` + /// + [Pure] + public string ToFullString(string separator = ", ") => + CollectionFormat.ToFullString(ValueTuples.Map(kv => $"({kv.Key}: {kv.Value})")); + + /// + /// Format the collection as `[(key: value), (key: value), (key: value), ...]` + /// + [Pure] + public string ToFullArrayString(string separator = ", ") => + CollectionFormat.ToFullArrayString(ValueTuples.Map(kv => $"({kv.Key}: {kv.Value})")); + + [Pure] public IEnumerable<(K Key, V Value)> AsEnumerable() => Value.AsEnumerable(); diff --git a/LanguageExt.Core/DataTypes/Map/Map.cs b/LanguageExt.Core/DataTypes/Map/Map.cs index 39f29e890..0f59df16b 100644 --- a/LanguageExt.Core/DataTypes/Map/Map.cs +++ b/LanguageExt.Core/DataTypes/Map/Map.cs @@ -658,6 +658,30 @@ IEnumerator IEnumerable.GetEnumerator() => public Seq<(K Key, V Value)> ToSeq() => Seq(this); + /// + /// Format the collection as `[(key: value), (key: value), (key: value), ...]` + /// The elipsis is used for collections over 50 items + /// To get a formatted string with all the items, use `ToFullString` + /// or `ToFullArrayString`. + /// + [Pure] + public override string ToString() => + CollectionFormat.ToShortArrayString(AsEnumerable().Map(kv => $"({kv.Key}: {kv.Value})"), Count); + + /// + /// Format the collection as `(key: value), (key: value), (key: value), ...` + /// + [Pure] + public string ToFullString(string separator = ", ") => + CollectionFormat.ToFullString(AsEnumerable().Map(kv => $"({kv.Key}: {kv.Value})")); + + /// + /// Format the collection as `[(key: value), (key: value), (key: value), ...]` + /// + [Pure] + public string ToFullArrayString(string separator = ", ") => + CollectionFormat.ToFullArrayString(AsEnumerable().Map(kv => $"({kv.Key}: {kv.Value})")); + [Pure] public IEnumerable<(K Key, V Value)> AsEnumerable() => Value.AsEnumerable(); diff --git a/LanguageExt.Core/DataTypes/Seq/Seq.cs b/LanguageExt.Core/DataTypes/Seq/Seq.cs index 59f311020..acc4da7d7 100644 --- a/LanguageExt.Core/DataTypes/Seq/Seq.cs +++ b/LanguageExt.Core/DataTypes/Seq/Seq.cs @@ -678,6 +678,32 @@ public override int GetHashCode() => ? hash(this) : hash; + /// + /// Format the collection as `[a, b, c, ...]` + /// The elipsis is used for collections over 50 items + /// To get a formatted string with all the items, use `ToFullString` + /// or `ToFullArrayString`. + /// + [Pure] + public override string ToString() => + Value is SeqLazy + ? CollectionFormat.ToShortArrayString(this) + : CollectionFormat.ToShortArrayString(this, Count); + + /// + /// Format the collection as `a, b, c, ...` + /// + [Pure] + public string ToFullString(string separator = ", ") => + CollectionFormat.ToFullString(this); + + /// + /// Format the collection as `[a, b, c, ...]` + /// + [Pure] + public string ToFullArrayString(string separator = ", ") => + CollectionFormat.ToFullArrayString(this); + /// /// Append operator /// diff --git a/LanguageExt.Core/DataTypes/Set/Set.cs b/LanguageExt.Core/DataTypes/Set/Set.cs index ee67ecb4d..d97063470 100644 --- a/LanguageExt.Core/DataTypes/Set/Set.cs +++ b/LanguageExt.Core/DataTypes/Set/Set.cs @@ -577,9 +577,29 @@ obj is Set && public override int GetHashCode() => Value.GetHashCode(); + /// + /// Format the collection as `[a, b, c, ...]` + /// The elipsis is used for collections over 50 items + /// To get a formatted string with all the items, use `ToFullString` + /// or `ToFullArrayString`. + /// [Pure] public override string ToString() => - $"Set[{Count}]"; + CollectionFormat.ToShortArrayString(this, Count); + + /// + /// Format the collection as `a, b, c, ...` + /// + [Pure] + public string ToFullString(string separator = ", ") => + CollectionFormat.ToFullString(this); + + /// + /// Format the collection as `[a, b, c, ...]` + /// + [Pure] + public string ToFullArrayString(string separator = ", ") => + CollectionFormat.ToFullArrayString(this); [Pure] public Seq ToSeq() => diff --git a/LanguageExt.Core/DataTypes/Stack/Stck.cs b/LanguageExt.Core/DataTypes/Stack/Stck.cs index 14c759de2..46f31eda7 100644 --- a/LanguageExt.Core/DataTypes/Stack/Stck.cs +++ b/LanguageExt.Core/DataTypes/Stack/Stck.cs @@ -94,6 +94,30 @@ public IEnumerator GetEnumerator() => public Seq ToSeq() => Seq(Value); + /// + /// Format the collection as `[a, b, c, ...]` + /// The elipsis is used for collections over 50 items + /// To get a formatted string with all the items, use `ToFullString` + /// or `ToFullArrayString`. + /// + [Pure] + public override string ToString() => + CollectionFormat.ToShortArrayString(this, Count); + + /// + /// Format the collection as `a, b, c, ...` + /// + [Pure] + public string ToFullString(string separator = ", ") => + CollectionFormat.ToFullString(this); + + /// + /// Format the collection as `[a, b, c, ...]` + /// + [Pure] + public string ToFullArrayString(string separator = ", ") => + CollectionFormat.ToFullArrayString(this); + /// /// Returns the stack as an IEnumerable. The first item in the enumerable /// will be the item at the top of the stack. diff --git a/LanguageExt.Core/Utility/CollectionFormat.cs b/LanguageExt.Core/Utility/CollectionFormat.cs index aa6e07168..688434078 100644 --- a/LanguageExt.Core/Utility/CollectionFormat.cs +++ b/LanguageExt.Core/Utility/CollectionFormat.cs @@ -1,25 +1,42 @@ using System; using System.Linq; using System.Collections.Generic; -using System.Text; namespace LanguageExt { public static class CollectionFormat { - public static string ToShortString(IEnumerable ma, string separator = ", ") + /// + /// Application wide setting for the maximum number of items + /// shown in a call to the `ToString` method of any LanguageExt + /// collection type. + /// + public static int MaxShortItems = 50; + + internal static string ToShortString(IEnumerable ma, string separator = ", ") { - var items = ma.Take(50).ToList(); - - if(items.Count < 50) - { - return $"{String.Join(separator, items)}"; - } - else - { - items.RemoveAt(49); - return $"{String.Join(separator, items)}..."; - } + var items = ma.Take(MaxShortItems).ToList(); + + return items.Count < MaxShortItems + ? $"{String.Join(separator, items)}" + : $"{String.Join(separator, items)} ..."; } + + internal static string ToShortString(IEnumerable ma, int count, string separator = ", ") => + count <= MaxShortItems + ? $"{String.Join(separator, ma)}" + : $"{String.Join(separator, ma.Take(MaxShortItems))} ... {count - MaxShortItems} more"; + + internal static string ToShortArrayString(IEnumerable ma, string separator = ", ") => + $"[{ToShortString(ma, separator)}]"; + + internal static string ToShortArrayString(IEnumerable ma, int count, string separator = ", ") => + $"[{ToShortString(ma, count, separator)}]"; + + internal static string ToFullString(IEnumerable ma, string separator = ", ") => + $"{String.Join(separator, ma)}"; + + internal static string ToFullArrayString(IEnumerable ma, string separator = ", ") => + $"[{ToFullString(ma, separator)}]"; } } diff --git a/LanguageExt.Tests/CollectionToStringTests.cs b/LanguageExt.Tests/CollectionToStringTests.cs new file mode 100644 index 000000000..1f36d2ccd --- /dev/null +++ b/LanguageExt.Tests/CollectionToStringTests.cs @@ -0,0 +1,112 @@ +using System; +using System.Linq; +using Xunit; +using static LanguageExt.Prelude; + +namespace LanguageExt.Tests +{ + public class CollectionToStringTests + { + readonly static int[] zeroToFour = Range(0, 5).ToArray(); + readonly static int[] zeroToFourtyNine = Range(0, 50).ToArray(); + readonly static int[] zeroToFiftyNine = Range(0, 60).ToArray(); + + readonly static string zeroToFourString = "[0, 1, 2, 3, 4]"; + readonly static string zeroToFourtyNineString = "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49]"; + readonly static string zeroToFiftyNineString = "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49 ... 10 more]"; + + readonly static (string, int)[] zeroToFourkeyValue = new[] { ("A", 0), ("B", 1), ("C", 2), ("D", 3), ("E", 4) }; + readonly static string zeroToFourKeyValueString = "[(A: 0), (B: 1), (C: 2), (D: 3), (E: 4)]"; + + [Fact] + public void ArrShortToString() + { + var items = toArray(zeroToFour); + Assert.True(items.ToString() == zeroToFourString); + } + + [Fact] + public void ArrMedToString() + { + var items = toArray(zeroToFourtyNine); + Assert.True(items.ToString() == zeroToFourtyNineString); + } + + [Fact] + public void ArrLongToString() + { + var items = toArray(zeroToFiftyNine); + Assert.True(items.ToString() == zeroToFiftyNineString); + } + + [Fact] + public void LstShortToString() + { + var items = toList(zeroToFour); + Assert.True(items.ToString() == zeroToFourString); + } + + [Fact] + public void LstMedToString() + { + var items = toList(zeroToFourtyNine); + Assert.True(items.ToString() == zeroToFourtyNineString); + } + + [Fact] + public void LstLongToString() + { + var items = toList(zeroToFiftyNine); + Assert.True(items.ToString() == zeroToFiftyNineString); + } + + [Fact] + public void SeqShortToString() + { + var items = Seq(zeroToFour); + Assert.True(items.ToString() == zeroToFourString); + } + + [Fact] + public void SeqMedToString() + { + var items = Seq(zeroToFourtyNine); + Assert.True(items.ToString() == zeroToFourtyNineString); + } + + [Fact] + public void SeqLongToString() + { + var items = Seq(zeroToFiftyNine); + Assert.True(items.ToString() == zeroToFiftyNineString); + } + + [Fact] + public void SetShortToString() + { + var items = toSet(zeroToFour); + Assert.True(items.ToString() == zeroToFourString); + } + + [Fact] + public void SetMedToString() + { + var items = toSet(zeroToFourtyNine); + Assert.True(items.ToString() == zeroToFourtyNineString); + } + + [Fact] + public void SetLongToString() + { + var items = toSet(zeroToFiftyNine); + Assert.True(items.ToString() == zeroToFiftyNineString); + } + + [Fact] + public void MapToString() + { + var items = toMap(zeroToFourkeyValue); + Assert.True(items.ToString() == zeroToFourKeyValueString); + } + } +} diff --git a/LanguageExt.Tests/ListTests.cs b/LanguageExt.Tests/ListTests.cs index bbdff2041..19715ca8b 100644 --- a/LanguageExt.Tests/ListTests.cs +++ b/LanguageExt.Tests/ListTests.cs @@ -174,7 +174,7 @@ public void UnfoldTest() { var test = List(0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181); - var fibs = take(unfold(Tuple(0, 1), tup => map(tup, (a, b) => Some(Tuple(a, Tuple(b, a + b))))), 20); + var fibs = take(unfold((0, 1), tup => map(tup, (a, b) => Some((a, (b, a + b))))), 20); Assert.True( test.SequenceEqual(fibs) ); } @@ -184,7 +184,7 @@ public void UnfoldTupleTest() { var test = List(0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181); - var fibs = take( unfold( Tuple(0, 1), (a, b) => Some(Tuple(a, b, a + b)) ), 20); + var fibs = take( unfold( (0, 1), (a, b) => Some((a, b, a + b)) ), 20); Assert.True(test.SequenceEqual(fibs)); }