Skip to content

Instantly share code, notes, and snippets.

Avatar
🐒

lukaszklekot

🐒
View GitHub Profile
@lukaszklekot
lukaszklekot / ContentView.swift
Last active Feb 26, 2020
Solution - SwiftUI Challenge #4: Aligning Two Columns https://twitter.com/objcio/status/1232682229710585856
View ContentView.swift
import SwiftUI
extension HorizontalAlignment {
private enum Column: AlignmentID {
static func defaultValue(in context: ViewDimensions) -> CGFloat {
fatalError("Missing alignment guide with id \(Self.self)")
}
}
static let column = HorizontalAlignment(Column.self)
View ContentView.swift
import SwiftUI
struct ContentView: View {
var body: some View {
TabBar(items: [
(Image(systemName: "tray"), Text("Inbox")),
(Image(systemName: "archivebox"), Text("Archive")),
(Image(systemName: "doc.text"), Text("Drafts")),
])
}
View Reader.swift
struct Reader<E, A> {
let run: (E) -> A
func map<B>(
_ t: @escaping (A) -> B
) -> Reader<E, B> {
diMap({ $0 }, t)
// .init { e in t(self.run(e)) }
}
@lukaszklekot
lukaszklekot / Contents.swift
Last active Jul 26, 2019
Fooling around with SwiftUI and The Elm Architecture
View Contents.swift
import Combine
import SwiftUI
final class Store<Model, Message>: BindableObject {
private(set) var model: Model {
willSet { willChange.send() }
}
let update: (inout Model, Message) -> Command<Message>?
let willChange = PassthroughSubject<Void, Never>()
@lukaszklekot
lukaszklekot / main.c
Created Nov 23, 2018
A crude C version of the "Composing state transformations from a list of simple functions" pattern; https://twitter.com/hukl/status/1065554266981625856
View main.c
#include <stdio.h>
double add_ten(double x) {
return x + 10;
}
double multiply_ten(double x) {
return x * 10;
}