Producer pattern in data types

This commit is contained in:
Michael Schimmel
2025-12-16 10:45:41 +01:00
parent 3c7723f3d2
commit 363c9596fc
5 changed files with 292 additions and 141 deletions
+25
View File
@@ -0,0 +1,25 @@
unit Myc.Ast.DataStream;
interface
uses
Myc.Data.Pipeline,
Myc.Data.Scalar;
type
// 1. IStreamProducer (Source)
// Provides data. Corresponds to IProducer<T>.
IStreamProducer = IProducer<IScalarRecordSeries>;
// 2. IStreamConsumer (Sink)
// Consumes data. Corresponds to IConsumer<T>.
IStreamConsumer = IConsumer<IScalarRecordSeries>;
// 3. IStreamConverter (Transform/Pipe)
// Consumes AND provides data.
// IMPORTANT: Inherits from IProducer, allowing safe hard-casts to IStreamProducer.
IStreamConverter = IConverter<IScalarRecordSeries, IScalarRecordSeries>;
implementation
end.
+33 -1
View File
@@ -25,7 +25,11 @@ type
stSeries,
stRecord,
stRecordSeries,
stGenericRecord
stGenericRecord,
// --- Pipeline Types ---
stStreamProducer, // Source
stStreamConverter, // Pipe (Source + Sink)
stStreamConsumer // Sink
);
TStaticTypeKindHelper = record helper for TStaticTypeKind
@@ -96,6 +100,15 @@ type
FText: IStaticType;
class var
FKeyword: IStaticType;
// Stream Types
class var
FStreamProducer: IStaticType;
class var
FStreamConverter: IStaticType;
class var
FStreamConsumer: IStaticType;
class constructor Create;
public
// Flyweight accessors
@@ -108,6 +121,11 @@ type
class property Text: IStaticType read FText;
class property Keyword: IStaticType read FKeyword;
// Stream Accessors
class property StreamProducer: IStaticType read FStreamProducer;
class property StreamConverter: IStaticType read FStreamConverter;
class property StreamConsumer: IStaticType read FStreamConsumer;
// Factory functions
class function CreateSeries(const AElementType: IStaticType): IStaticType; static;
class function CreateMethod(const AParamTypes: TArray<IStaticType>; const AReturnType: IStaticType): IStaticType; static;
@@ -170,6 +188,10 @@ begin
stRecord: Result := 'Record';
stRecordSeries: Result := 'RecordSeries';
stGenericRecord: Result := 'GenericRecord';
// New types
stStreamProducer: Result := 'StreamProducer';
stStreamConverter: Result := 'StreamConverter';
stStreamConsumer: Result := 'StreamConsumer';
else
Result := 'ErrorType';
end;
@@ -660,6 +682,11 @@ begin
FDateTime := TSimpleStaticType.Create(stDateTime);
FText := TSimpleStaticType.Create(stText);
FKeyword := TSimpleStaticType.Create(stKeyword);
// Initialize stream types
FStreamProducer := TSimpleStaticType.Create(stStreamProducer);
FStreamConverter := TSimpleStaticType.Create(stStreamConverter);
FStreamConsumer := TSimpleStaticType.Create(stStreamConsumer);
end;
class function TTypes.CreateMethod(const AParamTypes: TArray<IStaticType>; const AReturnType: IStaticType): IStaticType;
@@ -740,6 +767,11 @@ begin
if (Target.Kind = stOrdinal) and (Source.Kind = stKeyword) then
exit(True);
// Stream rules:
// A Converter IS a Producer.
if (Target.Kind = stStreamProducer) and (Source.Kind = stStreamConverter) then
exit(True);
Result := False;
end;