This file contains 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
collect(taskService.tasks) | |
.completeOnFailure() | |
.sink { [weak self] tasks in | |
print("Received \(tasks.count) tasks") | |
} | |
.store(in: &subscriptions) |
This file contains 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
import Combine | |
import Foundation | |
import shared | |
typealias OnEach<Output> = (Output) -> Void | |
typealias OnCompletion<Failure> = (Failure?) -> Void | |
typealias OnCollect<Output, Failure> = (@escaping OnEach<Output>, @escaping OnCompletion<Failure>) -> shared.Cancellable | |
/** |
This file contains 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
fun <T> Flow<T>.collect(onEach: (T) -> Unit, onCompletion: (cause: Throwable?) -> Unit): Cancellable { | |
val scope = CoroutineScope(SupervisorJob() + Dispatchers.Main) | |
scope.launch { | |
try { | |
collect { | |
onEach(it) | |
} | |
onCompletion(null) |
This file contains 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
interface TaskService { | |
val tasks: Flow<List<Task>> | |
fun tasks(onEach: (List<Task>) -> Unit, onCompletion: (Throwable?) -> Unit): Cancellable = | |
tasks.collect(onEach, onCompletion) | |
} |
This file contains 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
interface Cancellable { | |
fun cancel() | |
} |
This file contains 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
class AnyFlow<T>(source: Flow<T>): Flow<T> by source |
This file contains 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
class AnyFlow<T>(source: Flow<T>): Flow<T> by source { | |
fun collect(onEach: (T) -> Unit, onCompletion: (cause: Throwable?) -> Unit): Cancellable { | |
val scope = CoroutineScope(SupervisorJob() + Dispatchers.Main) | |
scope.launch { | |
try { | |
collect { | |
onEach(it) | |
} |
This file contains 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
/** | |
* Transforms Object into an array of key value pairs. | |
*/ | |
@Pipe({ name: 'entries' }) | |
export class KeyValueEntriesPipe implements PipeTransform { | |
transform<T extends { [p in keyof T]: T[keyof T] }>(input: T): { key: keyof T, value: T[keyof T] }[] { | |
const entries: { key: keyof T, value: T[keyof T] }[] = []; | |
for (const key in input) { | |
if (input.hasOwnProperty(key)) { | |
entries.push({ key, value: input[key] }); |
This file contains 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
#!/bin/sh | |
frameworks=$(otool -L $BUILT_PRODUCTS_DIR/$EXECUTABLE_PATH | pcregrep -o1 "@rpath/(.*?\.framework)") | |
index=0 | |
for framework in $frameworks; do | |
if [ -e "$SRCROOT/Carthage/Build/iOS/$framework" ]; then | |
export "SCRIPT_INPUT_FILE_$index"="$SRCROOT/Carthage/Build/iOS/$framework" | |
export "SCRIPT_OUTPUT_FILE_$index"="$BUILT_PRODUCTS_DIR/$FRAMEWORKS_FOLDER_PATH/$framework" | |
let index=index+1 |
This file contains 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
import UIKit | |
/** | |
Swizzles `addSubview` of `UIView`, replacing it with an implementatio that ensures it is always | |
invoked on the main thread. | |
Call this method in your application entry point, e.g. the `UIApplicationDelegate`. | |
*/ | |
func swizzleAddSubview() { | |
let clazz = UIView.self |