This file contains hidden or 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
request( loader, to:.load(.all(.lights)) ) | |
request( loader, to:.load(.all(.rooms )) ) |
This file contains hidden or 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
change(store, .by(.replacing(.lights(with:lights)))) |
This file contains hidden or 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
func createAdder(x:Int) -> (Int) -> Int { | |
var value = x | |
return { | |
value = value + $0; return value | |
} | |
} | |
let add = createAdder(x: 1) | |
add(2) // -> 3 | |
add(2) // -> 5 |
This file contains hidden or 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
func createLightingFeature(store : Store, | |
lightsStack: LightsStack, | |
output : @escaping Output) -> Input | |
{ | |
let loader = LightsLoader (lightsStack:lightsStack,store:store,responder:handle(output:output)) | |
let switcher = LightSwitcher (lightsStack:lightsStack,store:store,responder:handle(output:output)) | |
let valueSetter = LightValueSetter(lightsStack:lightsStack,store:store,responder:handle(output:output)) | |
let dimmer = Dimmer (lightsStack:lightsStack,store:store,responder:handle(output:output)) | |
let changer = LightChanger (lightsStack:lightsStack,store:store,responder:handle(output:output)) | |
This file contains hidden or 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
func request(_ dimmer:Dimmer, to r:Dimmer.Request) { dimmer.request(r) } | |
struct Dimmer: UseCase { | |
enum Request { case increase(Light.Value, by:Light.Value.Increment, on:Light ) | |
case decrease(Light.Value, by:Light.Value.Increment, on:Light ) } | |
enum Response { case increase(Light.Value, by:Light.Value.Increment, on:Light, Outcome) | |
case decrease(Light.Value, by:Light.Value.Increment, on:Light, Outcome) } | |
init(lightsStack: LightsStack, store: Store, responder: @escaping (Response) -> ()) { | |
self.lightsStack = lightsStack | |
self.store = store |
This file contains hidden or 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
typealias Stack<T> = (push:(T) -> (), pop:() -> (T?)) | |
func createStack<T>() -> Stack<T> { | |
var array:[T] = [] | |
return ( push: { array.append($0) }, | |
pop: { array.count > 0 ? array.remove(at: array.count - 1) : nil } ) | |
} | |
let s:Stack<Int> = createStack() | |
s.push(1) |
This file contains hidden or 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
//MARK: - Message | |
enum Message { | |
case lighting(_Lighting) | |
} | |
//MARK: - Common Lighting DSL Elements | |
enum Outcome { case succeeded, failed(Error?) } | |
enum Items { case lights, rooms } | |
enum Loaded { case lights([Light]), rooms([Room]) } | |
enum Turn { case on, off } |
This file contains hidden or 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
// MARK: - Executable Documentation | |
#if targetEnvironment(simulator) | |
import SwiftUI | |
enum LightingFeature { | |
static func Documentation () -> [(Message._Lighting,Message._Lighting,Message._Lighting)]{ | |
let l = Light(id: "1", name: "1") | |
let r = Room(id: "a", title: "a") | |
let e = LightError.unknown | |
let docs: [(Message._Lighting,Message._Lighting,Message._Lighting)] = | |
// These are examples for every lighting command and their possible responses. These colums do show all commands the Lighting Module |
This file contains hidden or 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
public func alter(_ light:Light, by changes:Light.Change...) -> Light { changes.reduce(light) { $0.alter($1) } } | |
public struct Light:Codable, Equatable, Identifiable { | |
public enum Change { | |
case renaming(_RenameIt); public enum _RenameIt { case it (to:String) } | |
case turning (_TurnIt ); public enum _TurnIt { case it (Turn) } | |
case adding (_Add ); public enum _Add { case mode (Light.Mode) } | |
case toggling(_Toggle ); public enum _Toggle { case display(to:Interface) } | |
case setting (_Set ); public enum _Set { | |
case hue (to:Double ) |
This file contains hidden or 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
public func change(_ state: AppState, _ change: [ AppState.Change ] ) -> AppState { state.alter(change) } | |
public struct AppState: Codable { | |
public enum Change: Equatable { | |
case by(_By); public enum _By: Equatable { | |
case adding(_Add); public enum _Add: Equatable { | |
case light(Light) } | |
case replacing(_Replace); public enum _Replace: Equatable { | |
case lights(with:[Light]) | |
case light (with:Light ) |