Skip to content

Instantly share code, notes, and snippets.

@onmyway133
Created July 4, 2018 14:22
Show Gist options
  • Save onmyway133/d1db5c118d2369156f660554f35d6e4a to your computer and use it in GitHub Desktop.
Save onmyway133/d1db5c118d2369156f660554f35d6e4a to your computer and use it in GitHub Desktop.
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