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
// | |
// Free.swift | |
// Swift_Extras | |
// | |
// Created by Robert Widmann on 9/19/14. | |
// Copyright (c) 2014 Robert Widmann. All rights reserved. | |
// | |
import Foundation |
public struct AnyEquatable: Equatable { | |
private let value: Any | |
private let equals: Any -> Bool | |
public init<E: Equatable>(_ value: E) { | |
self.value = value | |
self.equals = { ($0 as? E == value) ?? false } | |
} | |
} |
extension RawRepresentable where Self: Hashable { | |
private static func iterateEnum<T: Hashable>(_: T.Type) -> AnyIterator<T> { | |
var index = 0 | |
let closure: () -> T? = { | |
let next = withUnsafePointer(to: &index) { | |
$0.withMemoryRebound(to: T.self, capacity: 1) { $0.pointee } | |
} | |
guard next.hashValue == index else { return nil } |
protocol Expr { | |
static func lit(_ x: Int) -> Self | |
static func add(_ lhs: Self, _ rhs: Self) -> Self | |
} | |
extension Int : Expr { | |
static func lit(_ x : Int) -> Int { | |
return x; | |
} | |
static func add(_ lhs: Int, _ rhs: Int) -> Int { |
This is a curated list of iOS (Swift & ObjC) frameworks which are inspired by React and Elm.
// This example shows how higher-kinded types can be emulated in Swift today. | |
// It acheives correct typing at the cost of some boilerplate, manual lifting and an existential representation. | |
// The technique below was directly inspired by the paper Lightweight Higher-Kinded Polymorphism | |
// by Jeremy Yallop and Leo White found at http://ocamllabs.io/higher/lightweight-higher-kinded-polymorphism.pdf | |
/// `ConstructorTag` represents a type constructor. | |
/// `Argument` represents an argument to the type constructor. | |
struct Apply<ConstructorTag, Argument> { | |
/// An existential containing a value of `Constructor<Argument>` | |
/// Where `Constructor` is the type constructor represented by `ConstructorTag` |
// | |
// ViewController.swift | |
// Forms | |
// By Brandon Kase and Chris Eidhof | |
import UIKit | |
protocol Element { | |
associatedtype Input |
//: [Previous](@previous) | |
import Foundation | |
struct Counter { | |
var name: String = "" | |
var age: Int = 33 | |
enum Action { | |
case increment |
//: [Previous](@previous) | |
import Foundation | |
protocol Changable { | |
associatedtype Change | |
mutating func apply(_ diff: Change) | |
} | |
extension Array: Changable { |
enum Command { | |
case buttonTapped | |
case textChanged(String) | |
} | |
enum SideEffect<C> { | |
case anEvent(C) | |
case readFile((String) -> C) | |
// ... | |
} |