-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add Branch and Zip methods to fluent interface (#81)
- Loading branch information
Showing
25 changed files
with
335 additions
and
56 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Streamistry.Fluent; | ||
public abstract class BranchesBuilder<TInput> : IBuilder<IChainablePort[]> | ||
{ | ||
protected BasePipeBuilder<TInput> Upstream { get; } | ||
protected IChainablePort[]? Instances { get; set; } | ||
|
||
public BranchesBuilder(BasePipeBuilder<TInput> upstream) | ||
=> (Upstream) = (upstream); | ||
|
||
public IChainablePort[] BuildPipeElement() | ||
=> Instances ??= OnBuildPipeElement(); | ||
|
||
public abstract IChainablePort[] OnBuildPipeElement(); | ||
|
||
public Pipeline Build() | ||
{ | ||
BuildPipeElement(); | ||
return Instances![0].Pipe.Pipeline!; | ||
} | ||
} |
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,22 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Streamistry.Fluent; | ||
public abstract class BaseCombinatorBuilder<TOutput> : BasePipeBuilder<TOutput> | ||
{ | ||
protected IBuilder<IChainablePort[]> Upstream { get; } | ||
|
||
public BaseCombinatorBuilder(IBuilder<IChainablePort[]> upstream) | ||
: base() | ||
=> (Upstream) = (upstream); | ||
|
||
public BasePipeBuilder<TOutput> Checkpoint(out IChainablePort<TOutput> port) | ||
{ | ||
port = BuildPipeElement(); | ||
return this; | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
public abstract partial class BasePipeBuilder<TOutput> : IPipeBuilder<TOutput> | ||
{ | ||
public BranchesBuilder<TOutput, {{ generics | array.join ", " }}> Branch<{{ generics | array.join ", " }}>( | ||
{{- | ||
func concat; ret string.append "Func<BasePipeBuilder<TOutput>, BasePipeBuilder<T" $0 | string.append ">> upstream" | string.append $0; end | ||
indexes | array.each @concat | array.join ", " | ||
}}) | ||
=> new(this, upstream{{ indexes | array.join ", upstream" }}); | ||
} |
31 changes: 31 additions & 0 deletions
31
Streamistry.SourceGenerator/BasePipeBuilderSourceGenerator.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,31 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using Microsoft.CodeAnalysis.Text; | ||
using Microsoft.CodeAnalysis; | ||
using System.Resources; | ||
using Scriban; | ||
using System.Reflection; | ||
|
||
namespace Streamistry.SourceGenerator; | ||
|
||
[Generator] | ||
public class BasePipeBuilderSourceGenerator : BaseSourceGenerator | ||
{ | ||
public override string GenerateClasses() | ||
{ | ||
var sb = new StringBuilder(); | ||
sb.Append(ReadTemplate("Header.scriban")) | ||
.AppendLine() | ||
.AppendLine("namespace Streamistry.Fluent;") | ||
.AppendLine(); | ||
|
||
for (int i = MIN_CARDINALITY; i <= MAX_CARDINALITY; i++) | ||
{ | ||
sb.Append(GenerateClass(Classname, i)); | ||
sb.AppendLine(); | ||
} | ||
|
||
return sb.ToString(); | ||
} | ||
} |
Oops, something went wrong.