View StateToggle.swift
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 CounterView: View { | |
@State var count = 0 | |
var body: some View { | |
Text(String(count)) | |
Button("+ 1", action: { count = count + 1 }) | |
} | |
} |
View ObservedObjectAndStateObject.swift
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 | |
class Counter: ObservableObject { | |
@Published var count: Int | |
init(_ count: Int) { | |
self.count = count | |
} | |
func increment() { |
View ObservedObjectReset.swift
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 | |
class Counter: ObservableObject { | |
@Published var count: Int | |
init(_ count: Int) { | |
self.count = count | |
} | |
func increment() { |
View ObservedObject.swift
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 | |
class Counter: ObservableObject { | |
@Published var count: Int | |
init(_ count: Int) { | |
self.count = count | |
} | |
func increment() { |
View StateReferenceTypeFixed.swift
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 | |
class Counter { | |
var count: Int | |
init(_ count: Int) { | |
self.count = count | |
} | |
func increment() { |
View StateReferenceTypeBroken.swift
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 | |
class Counter { | |
var count: Int | |
init(_ count: Int) { | |
self.count = count | |
} | |
func increment() { |
View Counter.swift
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 Counter: View { | |
@State var count: Int = 0 | |
init() { | |
print("Counter Created") | |
} | |
var body: some View { |
View init.lua
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
-- put into ~/.hammerspoon | |
-- map Caps Lock key to Control in macOS settings (Keyboard -> Modifier Keys...) | |
-- Give all the accessability permissions in Hammerspoon preferences | |
local function pressFn(mods, key) | |
if key == nil then | |
key = mods | |
mods = {} | |
end |
View Maybe-monad.js
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
export class Maybe<T> { | |
value: T | null | |
constructor(value: T | null) { | |
this.value = value | |
} | |
static property<P>(value: P | undefined): Maybe<P> { | |
if (value === undefined) { | |
return new Maybe<P>(null) |
View monad.js
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
function square (x) { | |
return [x * x, () => console.log(x * x)] | |
} | |
function feet (x) { | |
return [x * 3.28084, () => console.log(x * 3.28084)] | |
} | |
function compose (fn1, fn2) { | |
return (x) => fn2(fn1(x)) |
NewerOlder