Skip to content

Instantly share code, notes, and snippets.

@wildthink
wildthink / ResultBuilder.swift
Last active April 14, 2022 23:32
Default @resultBuilder implementation makes make Result Builder easy
import Foundation
// WildThink
// https://gist.github.com/wildthink/386305f84d1e3ec0e1a198656733babe
// refs:
// https://github.com/apple/swift-evolution/blob/main/proposals/0289-result-builders.md#virtualized-abstract-syntax-trees-asts
public indirect enum ResultBuilderTerm<Expression> {
case expression(Expression)
case lambda(() -> Expression)
case block([ResultBuilderTerm])
@wildthink
wildthink / Dieter_Rams.md
Created September 17, 2021 09:38
Dieter Rams' principles of good design applied to software engineering

Dieter Rams' principles of good design applied to software engineering

1. Good software is innovative

Rebuild old software using new technology. Build new software using old and stable technology.

Strive to bring something new into the world, even when building a clone. Observe the users for inspiration. Try to anticipate them: what will they really need next?

2. Good software is useful

@wildthink
wildthink / DraggableView.swift
Last active October 2, 2021 10:02 — forked from ohayon/DraggableView.swift
Example of making a reusable `draggable()` modifier for SwiftUI Views
//
// DraggableView.swift
// Created by Jason Jobe on 9/15/21.
//
import SwiftUI
public struct DraggableView: ViewModifier {
public enum Axis { case x, y, xy }
//
// RatingsView.swift
// RatingsView
//
// Created by Jason Jobe on 9/12/21.
//
import SwiftUI
public struct RatingsView: View {
var rating: CGFloat
@wildthink
wildthink / transducer-type.swift
Created September 10, 2021 09:43 — forked from hsavit1/transducer-type.swift
How to get a transducer type without higher kinds
import Foundation
// A bunch of convenience things
func const <A, B> (b: B) -> A -> B {
return { _ in b }
}
func repeat <A> (n: Int) -> A -> [A] {
return { a in
return map(Array(1...n), const(a))
}
@wildthink
wildthink / SnapCarousel.swift
Created September 8, 2021 09:54 — forked from xtabbas/SnapCarousel.swift
A carousel that snap items in place build on top of SwiftUI
//
// SnapCarousel.swift
// prototype5
//
// Created by xtabbas on 5/7/20.
// Copyright © 2020 xtadevs. All rights reserved.
//
import SwiftUI
@wildthink
wildthink / TwoWaySnapList.swift
Created September 1, 2021 03:18 — forked from sameersyd/TwoDirectionalSnapList.swift
SwiftUI - Two Directional SnapList
// Checkout the explanation article here - https://sameer-syd.medium.com/swiftui-two-directional-snaplist-95cb852957be
import SwiftUI
import Combine
struct HomeView: View {
@StateObject var viewModel: HomeViewModel
@wildthink
wildthink / ScrollableView.swift
Created August 31, 2021 21:12 — forked from jfuellert/ScrollableView.swift
A scrollable SwiftUI view, UIScrollView wrapper. ScrollableView lets you read and write content offsets for scrollview in SwiftUI, with and without animations.
import SwiftUI
struct ScrollableView<Content: View>: UIViewControllerRepresentable, Equatable {
// MARK: - Coordinator
final class Coordinator: NSObject, UIScrollViewDelegate {
// MARK: - Properties
private let scrollView: UIScrollView
var offset: Binding<CGPoint>
@wildthink
wildthink / EasyMeasurements.swift
Last active November 10, 2021 04:12
Syntactic Sugar for Measurements in Swift
import Foundation
public typealias Mass = Measurement<UnitMass>
public typealias Duration = Measurement<UnitDuration>
public typealias Angle = Measurement<UnitAngle>
public typealias Length = Measurement<UnitLength>
public typealias Speed = Measurement<UnitSpeed>
public extension Measurement where UnitType: Dimension {
static var zero: Measurement<UnitType> {
@wildthink
wildthink / property-key-paths.swift
Created May 29, 2021 15:37 — forked from rxwei/property-key-paths.swift
StoredPropertyIterable + CustomKeyPathIterable
//============================================================================//
// Part 1. StoredPropertyIterable
// This models the purely static layout of a struct.
//============================================================================//
// This is an implementation detail that is required before PAT existentials are
// possible.
protocol _StoredPropertyIterableBase {
static var _allStoredPropertiesTypeErased: [AnyKeyPath] { get }
static var _recursivelyAllStoredPropertiesTypeErased: [AnyKeyPath] { get }