Skip to content

Commit

Permalink
Collection ToString, ToFullString, ToFullArrayString
Browse files Browse the repository at this point in the history
  • Loading branch information
louthy committed Jan 12, 2020
1 parent d0f5eaa commit 2cc42b4
Show file tree
Hide file tree
Showing 16 changed files with 456 additions and 16 deletions.
24 changes: 24 additions & 0 deletions LanguageExt.Core/DataTypes/Arr/Arr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,30 @@ public IEnumerable<A> AsEnumerable() =>
public Seq<A> ToSeq() =>
Seq(this);

/// <summary>
/// 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`.
/// </summary>
[Pure]
public override string ToString() =>
CollectionFormat.ToShortArrayString(this, Count);

/// <summary>
/// Format the collection as `a, b, c, ...`
/// </summary>
[Pure]
public string ToFullString(string separator = ", ") =>
CollectionFormat.ToFullString(this);

/// <summary>
/// Format the collection as `[a, b, c, ...]`
/// </summary>
[Pure]
public string ToFullArrayString(string separator = ", ") =>
CollectionFormat.ToFullArrayString(this);

[Pure]
public IEnumerable<A> Skip(int amount) =>
Value.Skip(amount);
Expand Down
24 changes: 24 additions & 0 deletions LanguageExt.Core/DataTypes/HashMap/HashMap.Eq.cs
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,30 @@ IEnumerator IEnumerable.GetEnumerator() =>
public Seq<(K Key, V Value)> ToSeq() =>
Seq(Value.AsEnumerable());

/// <summary>
/// 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`.
/// </summary>
[Pure]
public override string ToString() =>
CollectionFormat.ToShortArrayString(AsEnumerable().Map(kv => $"({kv.Key}: {kv.Value})"), Count);

/// <summary>
/// Format the collection as `(key: value), (key: value), (key: value), ...`
/// </summary>
[Pure]
public string ToFullString(string separator = ", ") =>
CollectionFormat.ToFullString(AsEnumerable().Map(kv => $"({kv.Key}: {kv.Value})"));

/// <summary>
/// Format the collection as `[(key: value), (key: value), (key: value), ...]`
/// </summary>
[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();
Expand Down
24 changes: 24 additions & 0 deletions LanguageExt.Core/DataTypes/HashMap/HashMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,30 @@ IEnumerator IEnumerable.GetEnumerator() =>
public Seq<(K Key, V Value)> ToSeq() =>
Seq(AsEnumerable());

/// <summary>
/// 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`.
/// </summary>
[Pure]
public override string ToString() =>
CollectionFormat.ToShortArrayString(AsEnumerable().Map(kv => $"({kv.Key}: {kv.Value})"), Count);

/// <summary>
/// Format the collection as `(key: value), (key: value), (key: value), ...`
/// </summary>
[Pure]
public string ToFullString(string separator = ", ") =>
CollectionFormat.ToFullString(AsEnumerable().Map(kv => $"({kv.Key}: {kv.Value})"));

/// <summary>
/// Format the collection as `[(key: value), (key: value), (key: value), ...]`
/// </summary>
[Pure]
public string ToFullArrayString(string separator = ", ") =>
CollectionFormat.ToFullArrayString(AsEnumerable().Map(kv => $"({kv.Key}: {kv.Value})"));

[Pure]
public IEnumerable<(K Key, V Value)> AsEnumerable() =>
Value;
Expand Down
24 changes: 24 additions & 0 deletions LanguageExt.Core/DataTypes/HashSet/HashSet.Eq.cs
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,30 @@ IEnumerator IEnumerable.GetEnumerator() =>
public Seq<A> ToSeq() =>
Prelude.Seq(this);

/// <summary>
/// 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`.
/// </summary>
[Pure]
public override string ToString() =>
CollectionFormat.ToShortArrayString(this, Count);

/// <summary>
/// Format the collection as `a, b, c, ...`
/// </summary>
[Pure]
public string ToFullString(string separator = ", ") =>
CollectionFormat.ToFullString(this);

/// <summary>
/// Format the collection as `[a, b, c, ...]`
/// </summary>
[Pure]
public string ToFullArrayString(string separator = ", ") =>
CollectionFormat.ToFullArrayString(this);

[Pure]
public IEnumerable<A> AsEnumerable() =>
this;
Expand Down
24 changes: 24 additions & 0 deletions LanguageExt.Core/DataTypes/HashSet/HashSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,30 @@ IEnumerator IEnumerable.GetEnumerator() =>
public Seq<A> ToSeq() =>
Prelude.Seq(this);

/// <summary>
/// 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`.
/// </summary>
[Pure]
public override string ToString() =>
CollectionFormat.ToShortArrayString(this, Count);

/// <summary>
/// Format the collection as `a, b, c, ...`
/// </summary>
[Pure]
public string ToFullString(string separator = ", ") =>
CollectionFormat.ToFullString(this);

/// <summary>
/// Format the collection as `[a, b, c, ...]`
/// </summary>
[Pure]
public string ToFullArrayString(string separator = ", ") =>
CollectionFormat.ToFullArrayString(this);

[Pure]
public IEnumerable<A> AsEnumerable() =>
this;
Expand Down
24 changes: 24 additions & 0 deletions LanguageExt.Core/DataTypes/List/Lst.Predicate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,30 @@ IEnumerator<A> IEnumerable<A>.GetEnumerator() =>
public Seq<A> ToSeq() =>
Seq(this);

/// <summary>
/// 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`.
/// </summary>
[Pure]
public override string ToString() =>
CollectionFormat.ToShortArrayString(this, Count);

/// <summary>
/// Format the collection as `a, b, c, ...`
/// </summary>
[Pure]
public string ToFullString(string separator = ", ") =>
CollectionFormat.ToFullString(this);

/// <summary>
/// Format the collection as `[a, b, c, ...]`
/// </summary>
[Pure]
public string ToFullArrayString(string separator = ", ") =>
CollectionFormat.ToFullArrayString(this);

[Pure]
public IEnumerable<A> AsEnumerable() =>
this;
Expand Down
24 changes: 24 additions & 0 deletions LanguageExt.Core/DataTypes/List/Lst.Predicate2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,30 @@ public IEnumerator<A> GetEnumerator() =>
public Seq<A> ToSeq() =>
Seq(this);

/// <summary>
/// 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`.
/// </summary>
[Pure]
public override string ToString() =>
CollectionFormat.ToShortArrayString(this, Count);

/// <summary>
/// Format the collection as `a, b, c, ...`
/// </summary>
[Pure]
public string ToFullString(string separator = ", ") =>
CollectionFormat.ToFullString(this);

/// <summary>
/// Format the collection as `[a, b, c, ...]`
/// </summary>
[Pure]
public string ToFullArrayString(string separator = ", ") =>
CollectionFormat.ToFullArrayString(this);

[Pure]
public IEnumerable<A> AsEnumerable() =>
this;
Expand Down
24 changes: 24 additions & 0 deletions LanguageExt.Core/DataTypes/List/Lst.cs
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,30 @@ IEnumerator<A> IEnumerable<A>.GetEnumerator() =>
public Seq<A> ToSeq() =>
Seq(this);

/// <summary>
/// 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`.
/// </summary>
[Pure]
public override string ToString() =>
CollectionFormat.ToShortArrayString(this, Count);

/// <summary>
/// Format the collection as `a, b, c, ...`
/// </summary>
[Pure]
public string ToFullString(string separator = ", ") =>
CollectionFormat.ToFullString(this);

/// <summary>
/// Format the collection as `[a, b, c, ...]`
/// </summary>
[Pure]
public string ToFullArrayString(string separator = ", ") =>
CollectionFormat.ToFullArrayString(this);

[Pure]
public IEnumerable<A> AsEnumerable() =>
this;
Expand Down
25 changes: 25 additions & 0 deletions LanguageExt.Core/DataTypes/Map/Map.Ord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,31 @@ IEnumerator IEnumerable.GetEnumerator() =>
public Seq<(K Key, V Value)> ToSeq() =>
Seq(this);

/// <summary>
/// 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`.
/// </summary>
[Pure]
public override string ToString() =>
CollectionFormat.ToShortArrayString(ValueTuples.Map(kv => $"({kv.Key}: {kv.Value})"), Count);

/// <summary>
/// Format the collection as `(key: value), (key: value), (key: value), ...`
/// </summary>
[Pure]
public string ToFullString(string separator = ", ") =>
CollectionFormat.ToFullString(ValueTuples.Map(kv => $"({kv.Key}: {kv.Value})"));

/// <summary>
/// Format the collection as `[(key: value), (key: value), (key: value), ...]`
/// </summary>
[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();
Expand Down
24 changes: 24 additions & 0 deletions LanguageExt.Core/DataTypes/Map/Map.cs
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,30 @@ IEnumerator IEnumerable.GetEnumerator() =>
public Seq<(K Key, V Value)> ToSeq() =>
Seq(this);

/// <summary>
/// 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`.
/// </summary>
[Pure]
public override string ToString() =>
CollectionFormat.ToShortArrayString(AsEnumerable().Map(kv => $"({kv.Key}: {kv.Value})"), Count);

/// <summary>
/// Format the collection as `(key: value), (key: value), (key: value), ...`
/// </summary>
[Pure]
public string ToFullString(string separator = ", ") =>
CollectionFormat.ToFullString(AsEnumerable().Map(kv => $"({kv.Key}: {kv.Value})"));

/// <summary>
/// Format the collection as `[(key: value), (key: value), (key: value), ...]`
/// </summary>
[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();
Expand Down
26 changes: 26 additions & 0 deletions LanguageExt.Core/DataTypes/Seq/Seq.cs
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,32 @@ public override int GetHashCode() =>
? hash(this)
: hash;

/// <summary>
/// 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`.
/// </summary>
[Pure]
public override string ToString() =>
Value is SeqLazy<A>
? CollectionFormat.ToShortArrayString(this)
: CollectionFormat.ToShortArrayString(this, Count);

/// <summary>
/// Format the collection as `a, b, c, ...`
/// </summary>
[Pure]
public string ToFullString(string separator = ", ") =>
CollectionFormat.ToFullString(this);

/// <summary>
/// Format the collection as `[a, b, c, ...]`
/// </summary>
[Pure]
public string ToFullArrayString(string separator = ", ") =>
CollectionFormat.ToFullArrayString(this);

/// <summary>
/// Append operator
/// </summary>
Expand Down
22 changes: 21 additions & 1 deletion LanguageExt.Core/DataTypes/Set/Set.cs
Original file line number Diff line number Diff line change
Expand Up @@ -577,9 +577,29 @@ obj is Set<A> &&
public override int GetHashCode() =>
Value.GetHashCode();

/// <summary>
/// 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`.
/// </summary>
[Pure]
public override string ToString() =>
$"Set[{Count}]";
CollectionFormat.ToShortArrayString(this, Count);

/// <summary>
/// Format the collection as `a, b, c, ...`
/// </summary>
[Pure]
public string ToFullString(string separator = ", ") =>
CollectionFormat.ToFullString(this);

/// <summary>
/// Format the collection as `[a, b, c, ...]`
/// </summary>
[Pure]
public string ToFullArrayString(string separator = ", ") =>
CollectionFormat.ToFullArrayString(this);

[Pure]
public Seq<A> ToSeq() =>
Expand Down
Loading

0 comments on commit 2cc42b4

Please sign in to comment.