diff --git a/Sources/Verge/Store/Pipeline.swift b/Sources/Verge/Store/Pipeline.swift index b42481988f..8687351180 100644 --- a/Sources/Verge/Store/Pipeline.swift +++ b/Sources/Verge/Store/Pipeline.swift @@ -226,52 +226,6 @@ public enum Pipelines { ) } } - - public struct BasicMapPipeline: PipelineType { - - public typealias Storage = Void - - // MARK: - Properties - - public let map: (Input) -> Output - public let additionalDropCondition: ((Input) -> Bool)? - - public init( - map: @escaping (Input) -> Output, - additionalDropCondition: ((Input) -> Bool)? - ) { - self.map = map - self.additionalDropCondition = additionalDropCondition - } - - // MARK: - Functions - - public func yieldContinuously(_ input: Input, storage: Storage) -> ContinuousResult { - - guard let additionalDropCondition = additionalDropCondition, additionalDropCondition(input) else { - return .new(yield(input, storage: storage)) - } - - return .noUpdates - - } - - public func yield(_ input: Input, storage: Storage) -> Output { - map(input) - } - - public func drop(while predicate: @escaping (Input) -> Bool) -> Self { - return .init( - map: map, - additionalDropCondition: additionalDropCondition.map { currentCondition in - { input in - currentCondition(input) || predicate(input) - } - } ?? predicate - ) - } - - } public struct UniqueFilterEquatable: PipelineType where Map.Output : Equatable { @@ -374,7 +328,27 @@ public struct AnyMapFunction: MapFunction { } } -extension Pipelines { +extension PipelineType { + + public static func uniqueMap(_ mapFunction: Map) -> Self + where Map.Output: Equatable, Self == Pipelines.UniqueFilterEquatable { + return .init(map: mapFunction) + } + + public static func uniqueMap(_ map: @escaping @Sendable (Input) -> Output) -> Self + where Output: Equatable, Self == Pipelines.UniqueFilterEquatable> { + return uniqueMap(.init(map)) + } + + public static func uniqueMap(_ mapFunction: Map, _ outputComparator: OutputComparator) -> Self + where Self == Pipelines.UniqueFilter { + return .init(map: mapFunction, outputComparator: outputComparator) + } + + public static func uniqueMap(_ map: @escaping @Sendable (Input) -> Output, _ outputComparator: OutputComparator) -> Self + where Self == Pipelines.UniqueFilter, OutputComparator> { + return .init(map: .init(map), outputComparator: outputComparator) + } }