Skip to content

Instantly share code, notes, and snippets.

@rayfix
rayfix / boolean-sequences.swift
Created Jul 10, 2021
R-Style Boolean Sequence Selectors in Swift
View boolean-sequences.swift
extension Sequence where Element: Comparable {
static func ==(_ lhs: Self, _ rhs: Element) -> LazyMapSequence<Self, Bool> {
lhs.lazy.map { $0 == rhs }
}
static func !=(_ lhs: Self, _ rhs: Element) -> LazyMapSequence<Self, Bool> {
lhs.lazy.map { $0 != rhs }
}
static func <(_ lhs: Self, _ rhs: Element) -> LazyMapSequence<Self, Bool> {
View CowType.swift
//
// ContentView.swift
// CopyOnWrite
//
// Created by Ray Fix on 3/27/21.
//
import SwiftUI
struct CowType {
View VolumeView.swift
//
// ContentView.swift
// Slider
//
// Created by Ray Fix on 2/20/21.
//
import SwiftUI
struct VolumeView: View {
View PickerExample.swift
//
// ContentView.swift
// PickerDemo2
//
// Created by Ray Fix on 1/23/21.
//
import SwiftUI
View SmallArrayEnum.swift
// A slitghtly silly example of a fixed array prototype
enum SmallArrayEnum<E>: RandomAccessCollection, MutableCollection {
init() {
self = .count0
}
var startIndex: Int { 0 }
var endIndex: Int {
@rayfix
rayfix / DataGrid.swift
Created Nov 14, 2020
A SwiftUI 2D Grid
View DataGrid.swift
//
// ContentView.swift
// DataGrid
//
// Created by Ray Fix on 11/14/20.
//
import SwiftUI
struct DataGrid<Element> {
View PhotoPicker2.swift
//
// ContentView.swift
// PhotoPicker2
//
// Created by Ray Fix on 10/31/20.
//
import SwiftUI
import PhotosUI
import UIKit
View ImagePicker.swift
import SwiftUI
import PhotosUI
final class ViewModel: ObservableObject {
@Published var image: UIImage?
}
struct Spinner: UIViewRepresentable {
let isAnimating: Bool
View PRNG.swift
// Algorithm from https://en.wikipedia.org/wiki/Permuted_congruential_generator
struct PRNG: RandomNumberGenerator {
var state: UInt64 = 0x4d595df4d0f33173
let multiplier: UInt64 = 6364136223846793005
let increment: UInt64 = 1442695040888963407
init(seed: UInt64) {
state = seed &+ increment
View mocking.swift
import Combine
struct Location {
}
//protocol WeatherService {
// func getTemperature(location: Location) -> AnyPublisher<Double, Error>
//}
//