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
struct State1 { | |
var foo1: Int | |
} | |
struct State2 { | |
var bar2: Bool | |
} | |
// Q. How to make a "flattened" `struct State1_2 { var foo1: Int, var bar2: Bool }` | |
// from `State1` and `State2`? (a.k.a. extensible record / intersection type)? |
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
@propertyWrapper | |
class Box<T> { | |
var wrappedValue: T | |
var projectedValue: Box<T> { | |
Box(wrappedValue) | |
} | |
init(_ value: T) { | |
self.wrappedValue = value |
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
/// Pseudo-Swift: public / fileprivate enum cases | |
public enum Action { | |
public case foo | |
public case bar(Int) | |
// fileprivate enum cases, where pattern matches are only allowed in this file. | |
// From outside, only using switch statement's `default` is possible. | |
// (NOTE: `private` won't make sense) | |
// | |
// This is useful to define private-Action values. |
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
/// Swift do-defer-guard test | |
func test(pass: Bool) { | |
do { | |
print("1. start of scope") | |
defer { print("3. deferred") } | |
guard pass else { return } | |
print("2. end of scope") | |
} |
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 XCTest | |
import Combine | |
class DeinitTimingTests: XCTestCase { | |
func testExample() throws { | |
let publisher = PassthroughSubject<Void, Never>() | |
var cancellables = Set<AnyCancellable>() | |
var isDone = false |
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
{-# LANGUAGE RankNTypes #-} | |
module Church where | |
-- Church encoding of boolean. | |
-- 1st arg as `true`, 2nd arg as `false`. | |
type Bool' = forall x. x -> x -> x | |
true :: Bool' | |
true = \t f -> t |
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
flipAll2 :: (t1 -> t2 -> t3) -> t2 -> t1 -> t3 | |
flipAll2 = flip | |
-- flip 1st & 2nd arg | |
flipAll3 :: (t1 -> t2 -> t3 -> t4) -> t3 -> t2 -> t1 -> t4 | |
flipAll3 = flipAll2 . (flip .) . flip | |
-- flip 1st & 2nd arg, 2nd & 3rd arg, goto flipAll2 | |
flipAll4 :: (t1 -> t2 -> t3 -> t4 -> t5) -> t4 -> t3 -> t2 -> t1 -> t5 | |
flipAll4 = flipAll3 . ((flip .) .) . (flip .) . flip |
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 SwiftUI | |
struct ContentView: View { | |
@UseCounter | |
var counter: Int = 0 | |
@UseCounterEffect(initialCount: 1, onUpdate: { count in | |
print("===> update: \(count)") | |
}) | |
var counterEffect: Void |
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
-- For all `x` that is prefixed point of `f` (f x :< x), | |
-- it is upper bound of `f^n ⊥` (where n = 0, 1, 2, ...) | |
-- so that its least upper bound `Mu f` is always less than or equal to `x`. | |
cata :: (f x :< x) -> Mu f :< x | |
-- For all `x` that is postfixed point of `f` (x :< f x), | |
-- it is lower bound of `f^n ⊤` (where n = 0, 1, 2, ...) | |
-- so that its greatest lower bound `Nu f` is always greater than or equal to `x`. | |
ana : (x :< f x) -> x :< Nu f |
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
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void | |
? I | |
: never | |
type FunctionUnion = (() => void) | ((p: string) => void) | |
type FunctionIntersection = UnionToIntersection<FunctionUnion> | |
// (() => void) & ((p: string) => void) |