Skip to content

Instantly share code, notes, and snippets.

View Nillerr's full-sized avatar

Nicklas Jensen Nillerr

View GitHub Profile
abstract class BeforeSuiteExtension : BeforeAllCallback, ExtensionContext.Store.CloseableResource {
companion object {
@JvmStatic
private val lock = ReentrantLock()
@JvmStatic
private var isStarted: Boolean = false
}
func combineLatest<A, B, R>(_ aSequence: A, _ bSequence: B, transform: @escaping (A.Element, B.Element) -> R) -> AsyncStream<R> where A : AsyncSequence, B : AsyncSequence {
return AsyncStream { (continuation) async in
let aCurrentValue = Ref<A.Element?>(initialValue: nil)
let aTask = Ref<Task<Void, Error>?>(initialValue: nil)
let bCurrentValue = Ref<B.Element?>(initialValue: nil)
let bTask = Ref<Task<Void, Error>?>(initialValue: nil)
package com.cardlay.nebula.shared.query
class MapTree<K, V : Any> : MutableTree<K, V> {
private class MutableNode<K, V : Any> : Tree.Node<K, V> {
override val nodes = mutableMapOf<K, MutableNode<K, V>>()
override var value: V? = null
val size: Int
get() {
if (value != null) {
import Swinject
private let prefix = "<asOneOf:"
private func nameOf<T>(_ serviceType: T) -> String {
return "\(prefix):\(String(reflecting: serviceType))>"
}
class AggregateBehavior<Common> : Behavior {
private var factories: [(Resolver) -> Common?] = []
import Combine
enum PublisherTimeoutError<Failure>: Error where Failure: Error {
case failure(Failure)
case timeout
}
extension Publisher {
func timeoutToNil<S>(after interval: S.SchedulerTimeType.Stride, scheduler: S) -> AnyPublisher<Output?, Failure> where S: Scheduler {
mapError({ error -> PublisherTimeoutError<Failure> in .failure(error) })
@Nillerr
Nillerr / ObservableScrollView.swift
Created April 8, 2022 11:31
A `ScrollView` wrapper that provides the content size and offset through `@Binding`s, as well as a vertical `ScrollView` with a "scroll to bottom" button.
import Combine
import SwiftUI
/// Contains the gap between the smallest value for the y-coordinate of
/// the frame layer and the content layer.
private struct ContentOffsetPreferenceKey: PreferenceKey {
static var defaultValue: CGPoint = .zero
static func reduce(value: inout CGPoint, nextValue: () -> CGPoint) {}
}
@Nillerr
Nillerr / Future+Async.swift
Created February 18, 2022 09:50
Implements the `.value` async property for `Future` available since iOS 15.0
import Combine
extension Publishers {
struct MissingOutputError : Error {}
}
extension Future where Failure == Never {
var value: Output {
get async {
var cancellable: AnyCancellable? = nil

Flow Wrapper Function (Live Templates)

flow wrap

Creates a wrapper for a function returning Flow accepting no arguments

fun $NAME$(onEach: ($TYPE$) -> Unit, onCompletion: (Throwable?) -> Unit): Cancellable =
    $NAME$().collect(onEach, onCompletion)
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
/**
import Combine
import Foundation
import shared
extension KotlinThrowable: Error {
}
struct PublisherFailures {
/**
The action to invoke when a failure is dropped as the result of a `Publisher` returned by