-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from Mafii/partition-specialization
Add option to generate specialized partition implementation
- Loading branch information
Showing
46 changed files
with
710 additions
and
118 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
Funcky.DiscriminatedUnion.SourceGeneration/CollectingInterpolatedStringHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System.Runtime.CompilerServices; | ||
|
||
namespace Funcky.DiscriminatedUnion.SourceGeneration; | ||
|
||
[InterpolatedStringHandler] | ||
public readonly struct CollectingInterpolatedStringHandler | ||
{ | ||
public CollectingInterpolatedStringHandler(int literalLength, int formattedCount) | ||
{ | ||
_items = new List<object?>(formattedCount * 2); | ||
} | ||
|
||
public CollectingInterpolatedStringHandler() | ||
{ | ||
_items = new List<object?>(); | ||
} | ||
|
||
private readonly List<object?> _items; | ||
|
||
public IEnumerable<object?> GetItems() => _items; | ||
|
||
public void AppendLiteral(string s) => _items.Add(s); | ||
|
||
public void AppendFormatted<T>(T t) => _items.Add(t); | ||
|
||
public void AppendFormatted(CollectingInterpolatedStringHandler handler) | ||
=> _items.AddRange(handler._items); | ||
} |
53 changes: 53 additions & 0 deletions
53
Funcky.DiscriminatedUnion.SourceGeneration/CollectingInterpolatedStringHandlerExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
namespace Funcky.DiscriminatedUnion.SourceGeneration; | ||
|
||
public static class CollectingInterpolatedStringHandlerExtensions | ||
{ | ||
public static CollectingInterpolatedStringHandler JoinToInterpolation<T>( | ||
this IEnumerable<T> source, | ||
string separator) | ||
{ | ||
using var enumerator = source.GetEnumerator(); | ||
|
||
if (!enumerator.MoveNext()) | ||
{ | ||
return new CollectingInterpolatedStringHandler(); | ||
} | ||
|
||
var result = new CollectingInterpolatedStringHandler(); | ||
|
||
result.AppendFormatted(enumerator.Current); | ||
|
||
while (enumerator.MoveNext()) | ||
{ | ||
result.AppendLiteral(separator); | ||
result.AppendFormatted(enumerator.Current); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
public static CollectingInterpolatedStringHandler JoinToInterpolation<T>( | ||
this IEnumerable<T> source, | ||
Func<T, CollectingInterpolatedStringHandler> createPart, | ||
string separator) | ||
{ | ||
using var enumerator = source.GetEnumerator(); | ||
|
||
if (!enumerator.MoveNext()) | ||
{ | ||
return new CollectingInterpolatedStringHandler(); | ||
} | ||
|
||
var result = new CollectingInterpolatedStringHandler(); | ||
|
||
result.AppendFormatted(createPart(enumerator.Current)); | ||
|
||
while (enumerator.MoveNext()) | ||
{ | ||
result.AppendLiteral(separator); | ||
result.AppendFormatted(createPart(enumerator.Current)); | ||
} | ||
|
||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.