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
/// Wrapper around a lazily resolved using checked continuation. | |
/// | |
/// Usage: | |
/// | |
/// ``` | |
/// let promiseA = Promised<String>() | |
/// async let a1 = promiseA.value | |
/// promiseA.resolve("AAA") | |
/// let a2 = await promiseA.value | |
/// print(await a1, a2) |
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
/* | |
Inspired by https://forums.swift.org/t/running-an-async-task-with-a-timeout/49733 | |
*/ | |
/// - Throws: Throws `TimedOutError` if the timeout expires before `work` completes. | |
/// If `work` throws an error before the timeout expires, that error is propagated to the caller. | |
func withTimeout<R>( | |
_ maxDuration: TimeInterval, | |
returning returnType: R.Type = R.self, | |
work: @Sendable @escaping () async throws -> R |
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
//sourcery: mockEnvironment | |
struct Environment { | |
var call1: () -> Void | |
var call2: () -> Foo | |
var call3: (Foo) -> Void | |
var call4: (Foo, Bar) -> Bazel | |
} |
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
@resultBuilder | |
public struct ArrayBuilder<Element> { | |
public static func buildPartialBlock(first: Element) -> [Element] { [first] } | |
public static func buildPartialBlock(first: [Element]) -> [Element] { first } | |
public static func buildPartialBlock(accumulated: [Element], next: Element) -> [Element] { accumulated + [next] } | |
public static func buildPartialBlock(accumulated: [Element], next: [Element]) -> [Element] { accumulated + next } | |
// Empty Case | |
public static func buildBlock() -> [Element] { [] } | |
// If/Else |
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
// | |
// 98.swift | |
// | |
// Created by Rob Chatfield on 24/4/20. | |
// Inspired by (98.css)[https://jdan.github.io/98.css] | |
// Copyright © 2020 Rob Chatfield. All rights reserved. | |
// | |
import SwiftUI |
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
// LevenshteinDistance.swift | |
// | |
// Created by Rob Chatfield on 1 Apr 2020 | |
// Copyright 2020 Rob Chatfield. All rights reserved. | |
// | |
// This code is an updated Swift implementation based on "LevenshteinSwift" Created by Cory Alder. | |
// Which was based on the Objective-C "NSString+Levenshtein" Created by Mark Aufflick. | |
// Which was based loosely on the NSString(Levenshtein) code by Rick Bourner | |
// | |
// Improvements and suggestions welcome. |
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 | |
extension UITableView { | |
struct State { | |
var sections: [Section] | |
var sectionIndexTitles: [String]? | |
struct Section { | |
var rows: [Row] | |
var titleForHeader: String? |
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
final class BoardShortFetcher { | |
let projectRepo: ProjectRepository | |
let projectGateway: ProjectGateway | |
let boardShortRepo: BoardShortRepository | |
let boardShortGateway: BoardShortGateway | |
init() { fatalError() } | |
// Only entry point | |
func retreiveBoardShort(boardFeatureLocator: BoardFeatureLocator) -> Future<BoardShortEntity, Error> { |
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
/// Async code (one day) can be written in 3 ways: | |
/// 1. Callbacks | |
/// 2. Future | |
/// 3. async/await | |
/// | |
/// Let's explore how they work together by defining | |
/// `myClosure`, `myFuture` & `myFunction` | |
/// each derived from the other two approaches. | |
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 PlaygroundSupport | |
import SwiftUI | |
PlaygroundPage.current.setLiveView( | |
GridResultView.all() | |
//GridResultView.single(.expert) | |
) | |
// Times: "copy+solve solve (val solve)" | |
Grid.easy // 6ms 0ms ( 8ms) |
NewerOlder