Created
July 4, 2018 14:22
-
-
Save onmyway133/d1db5c118d2369156f660554f35d6e4a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
public struct PullSignal<T> { | |
let operation: ((Result<T>) -> Void) -> Void | |
public init(operation: @escaping ((Result<T>) -> Void) -> Void) { | |
self.operation = operation | |
} | |
public func start(completion: (Result<T>) -> Void) { | |
operation() { event in | |
completion(event) | |
} | |
} | |
public func map<U>(f: @escaping (T) -> U) -> PullSignal<U> { | |
return PullSignal<U> { completion in | |
self.start { event in | |
completion(event.map(f: f)) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment