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
private func fibonacci(_ n: Int) -> Int { | |
guard n != 0, n != 1 else { return n } | |
return fibonacci(n - 1) + fibonacci(n - 2) | |
} |
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
pico-8 cartridge // http://www.pico-8.com | |
version 18 | |
__lua__ | |
-- this is called automatically | |
-- one time when the game starts | |
-- but we'll call it again later | |
-- to start the game over | |
function _init() | |
-- later, when the game is over | |
-- we'll call this functiom |
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
struct Grid<T> { | |
let width: Int | |
let height: Int | |
private var gridData: [T] | |
init(width: Int, height: Int, initialFill: T) { | |
self.width = width | |
self.height = height | |
gridData = [T](repeating: initialFill, count: width * height) |
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
include "hardware.inc" ; https://github.com/gbdev/hardware.inc | |
; Constants | |
LCD_ON_BIT EQU 7 | |
LCD_BG_TILE_DATA_BIT EQU 4 | |
RUBY_TOP_VRAM EQU _VRAM | |
; Define a 2-byte RGB color | |
; | |
; /1 = R, /2 = G, /3 = B |
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
import Combine | |
import SwiftUI | |
extension Publisher { | |
func withPrevious(_ initial: Output) -> AnyPublisher<(Output, Output), Failure> { | |
scan((initial, initial)) { previousTuple, currentValue in | |
(previousTuple.1, currentValue) | |
}.eraseToAnyPublisher() | |
} | |
} |
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
import SwiftUI | |
/// A view which lazily initializes its content view. | |
struct LazyView<Content: View>: View { | |
private let viewBlock: () -> Content | |
init(_ content: @escaping @autoclosure () -> Content) { | |
viewBlock = content | |
} |
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
import Combine | |
@propertyWrapper | |
struct NextValue<Output> { | |
typealias Failure = Never | |
typealias Publisher = AnyPublisher<Output, Never> | |
var wrappedValue: Output { | |
willSet { | |
subject.send(newValue) |
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
struct SimpleView: View { | |
let name: String | |
let caption: String | |
var body: some View { | |
VStack(alignment: .leading) { | |
Text(name).font(.headline) | |
Text(caption).font(.subheadline) | |
} | |
} |
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
struct OptionalView<Value, Content: View>: View { | |
private let value: Value? | |
private let content: (Value) -> Content | |
init(_ value: Value?, content: @escaping (Value) -> Content) { | |
self.value = value | |
self.content = content | |
} | |
var body: AnyView { |
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
import Combine | |
struct ZipMany<Element, Failure>: Publisher where Failure: Error { | |
typealias Output = [Element] | |
private let underlying: AnyPublisher<Output, Failure> | |
init<T: Publisher>(publishers: [T]) where T.Output == Element, T.Failure == Failure { | |
let zipped: AnyPublisher<[T.Output], T.Failure>? = publishers.reduce(nil) { result, publisher in | |
if let result = result { |