-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSchemaBoundSource.cs
56 lines (43 loc) · 1.95 KB
/
SchemaBoundSource.cs
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
50
51
52
53
54
55
56
using System;
using Akka.Streams;
using Akka.Streams.Dsl;
using Arcane.Framework.Sinks.Base;
using Arcane.Framework.Sources.Base;
using Arcane.Framework.Sources.Extensions;
namespace Arcane.Framework.Sources;
/// <inheritdoc />
public class SchemaBoundSource<TOut, TMat, TSchema>: ISchemaBoundSource<TOut, TMat, TSchema> where TSchema : ISchemaValidator<TOut>
{
private readonly ISchemaFreeSource<TOut,TMat> source;
/// <summary>
/// Creates a new schema-bound source
/// </summary>
/// <param name="source">Underlying schema-free source</param>
/// <param name="schema">Data schema</param>
public SchemaBoundSource(ISchemaFreeSource<TOut, TMat> source, TSchema schema)
{
this.source = source;
this.Schema = schema;
}
/// <inheritdoc />
public TSchema Schema { get; }
/// <inheritdoc />
public IArcaneSource<TOut, TMat2> MapMaterializedValue<TMat2>(Func<TMat, TMat2> mapper) =>
this.source.MapMaterializedValue(mapper);
/// <inheritdoc />
public ISchemaFreeSource<TOut2, TMat> Map<TOut2>(Func<TOut, TOut2> mapper) => this.source.Map(mapper);
/// <inheritdoc />
public ISchemaFreeSource<TOut2, TMat> MapSource<TOut2>(Func<Source<TOut, TMat>, Source<TOut2, TMat>> mapper)
=> this.source.MapSource(mapper);
/// <inheritdoc />
public IRunnableGraph<TMat2> To<TMat2>(ISchemaFreeSink<TOut, TMat2> sink) => this.source.To(sink);
/// <inheritdoc />
public ISchemaFreeSource<TOut2, TMat> Via<TOut2>(IGraph<FlowShape<TOut, TOut2>, TMat> flow) =>
this.source.Via(flow);
/// <inheritdoc />
public ISchemaBoundSource<TOut2, TMat, TNewSchema> Map<TOut2, TNewSchema>(Func<TOut, TOut2> mapper, TNewSchema newSchema)
where TNewSchema : ISchemaValidator<TOut2> =>
this.source.Map(mapper).WithSchema(newSchema);
/// <inheritdoc />
public IRunnableGraph<TMat2> To<TMat2>(ISchemaBoundSink<TOut, TMat2, TSchema> sink) => sink.GraphBuilder(this);
}