summaryrefslogtreecommitdiffhomepage
path: root/ios/Operations/InputOperation.swift
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@mullvad.net>2022-09-25 16:34:23 +0200
committerAndrej Mihajlov <and@mullvad.net>2022-09-26 16:35:38 +0200
commitf389956c2cd884df142adbf00ff2ac7e2f69c2b2 (patch)
tree5f7d4869324760eb4ba0107c0356edc89efd1457 /ios/Operations/InputOperation.swift
parent2e83b1ca27ff243a615ff10c94c20840b38dfd45 (diff)
downloadmullvadvpn-f389956c2cd884df142adbf00ff2ac7e2f69c2b2.tar.xz
mullvadvpn-f389956c2cd884df142adbf00ff2ac7e2f69c2b2.zip
Move AsyncOperation into Operations static library and add separate tests
Diffstat (limited to 'ios/Operations/InputOperation.swift')
-rw-r--r--ios/Operations/InputOperation.swift47
1 files changed, 47 insertions, 0 deletions
diff --git a/ios/Operations/InputOperation.swift b/ios/Operations/InputOperation.swift
new file mode 100644
index 0000000000..9d88861f4d
--- /dev/null
+++ b/ios/Operations/InputOperation.swift
@@ -0,0 +1,47 @@
+//
+// InputOperation.swift
+// MullvadVPN
+//
+// Created by pronebird on 09/06/2022.
+// Copyright © 2022 Mullvad VPN AB. All rights reserved.
+//
+
+import Foundation
+
+public protocol InputOperation: Operation {
+ associatedtype Input
+
+ var input: Input? { get }
+
+ func setInputBlock(_ block: @escaping () -> Input?)
+
+ func inject<T>(from dependency: T)
+ where T: OutputOperation, T.Output == Input
+
+ func inject<T>(from dependency: T, via block: @escaping (T.Output) -> Input)
+ where T: OutputOperation
+}
+
+public extension InputOperation {
+ func inject<T>(from dependency: T) where T: OutputOperation, T.Output == Input {
+ inject(from: dependency, via: { $0 })
+ }
+
+ func inject<T>(from dependency: T, via block: @escaping (T.Output) -> Input)
+ where T: OutputOperation
+ {
+ setInputBlock {
+ return dependency.output.map { value in
+ return block(value)
+ }
+ }
+ addDependency(dependency)
+ }
+
+ func injectMany<Context>(context: Context) -> InputInjectionBuilder<Self, Context> {
+ return InputInjectionBuilder(
+ operation: self,
+ context: context
+ )
+ }
+}