This is a curated list of iOS (Swift & ObjC) frameworks which are inspired by React and Elm.
- ReactSwift by @ColinEberhardt
- https://github.com/ColinEberhardt/ReactSwift
import RxSwift | |
let subject = PublishSubject<Int>() | |
let flatMapped = subject | |
.flatMap { | |
// Choose one: | |
// 1. Observable<Int>.just($0) | |
// 2. Observable<Int>.just($0).values.asObservable() |
This is a curated list of iOS (Swift & ObjC) frameworks which are inspired by React and Elm.
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)? |
@propertyWrapper | |
class Box<T> { | |
var wrappedValue: T | |
var projectedValue: Box<T> { | |
Box(wrappedValue) | |
} | |
init(_ value: T) { | |
self.wrappedValue = value |
// Recursive opaque type fails compile because recursiveness can’t deterministically pick the right type to replace `some P`. | |
protocol P {} | |
struct Parent<Child: P>: P { | |
let children: [Child] | |
} | |
func recursive() -> some P { | |
// ERROR: Function opaque return type was inferred as 'Parent<some P>', which defines the opaque type in terms of itself |
@MainActor | |
class ViewModel: ObservableObject {} | |
@propertyWrapper | |
struct Wrapper<T> { | |
var wrappedValue: T | |
} | |
@propertyWrapper | |
struct MainWrapper<T> { |
import Foundation | |
import _Concurrency | |
extension AsyncStream { | |
public init<S: AsyncSequence & Sendable>( | |
_ sequence: S, | |
bufferingPolicy limit: Continuation.BufferingPolicy = .unbounded | |
) where S.Element == Element { | |
self.init(bufferingPolicy: limit) { continuation in | |
let task = Task { |
import SwiftUI | |
struct ContentView: View { | |
@UseCounter | |
var counter: Int = 0 | |
@UseCounterEffect(initialCount: 1, onUpdate: { count in | |
print("===> update: \(count)") | |
}) | |
var counterEffect: Void |
-- Solving Fix / Mu / Nu exercise in | |
-- https://stackoverflow.com/questions/45580858/what-is-the-difference-between-fix-mu-and-nu-in-ed-kmetts-recursion-scheme-pac | |
{-# LANGUAGE RankNTypes, GADTs #-} | |
---------------------------------------- | |
-- Fix / Mu / Nu | |
newtype Fix f = Fix { unFix :: f (Fix f) } |
func foo() throws -> Int { | |
1 | |
} | |
func fooAsync() async throws -> Int { | |
1 | |
} | |
class Foo { | |
var x: Int = 0 |