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
// | |
// main.swift | |
// banana | |
// | |
// Created by Greg Titus on 7/15/23. | |
// | |
import Foundation | |
import Cocoa |
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
// | |
// main.swift | |
// banana | |
// | |
// Created by Greg Titus on 7/15/23. | |
// | |
import Foundation | |
import Cocoa |
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
// | |
// main.swift | |
// banana | |
// | |
// Created by Greg Titus on 7/15/23. | |
// | |
import Foundation | |
enum Letter: Character, Hashable { |
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
// Returns a set of instructions in the form of an array of closed ranges, | |
// where you should swap the element at the lowerBound of the range continually forward until next to the upperBound, | |
// and then cancel. | |
func shortenList<T>(inputList: [T], cancellable: (T, T) -> Bool, swappable: (T, T) -> Bool) -> [ClosedRange<Int>] { | |
var list = inputList | |
var result: [ClosedRange<Int>] = [] | |
while list.count > 1 { | |
var cancelRange: ClosedRange<Int>? |
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
extension Range where Bound: Strideable { | |
func stride(by: Bound.Stride) -> StrideTo<Bound> { | |
Swift.stride(from: lowerBound, to: upperBound, by: by) | |
} | |
} | |
extension ClosedRange where Bound: Strideable { | |
func stride(by: Bound.Stride) -> StrideThrough<Bound> { | |
Swift.stride(from: lowerBound, through: upperBound, by: by) | |
} | |
} |
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
struct LazyChunkedOn<Base: Collection, Subject: Equatable> : Collection { | |
typealias Element = Base.SubSequence | |
var underlying: Base | |
var projection: (Base.Element) -> Subject | |
struct Index: Comparable { | |
let start: Base.Index | |
var subject: Subject? | |
static func == (lhs: Index, rhs: Index) -> Bool { lhs.start == rhs.start } |
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 UIKit | |
// Just hold a value in a class so that we can reference it. | |
private class XStateStorage<Value> { | |
var value: Value | |
init(value: Value) { | |
self.value = value | |
} | |
} |
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
struct SortedMergeSequence<Element: Comparable> : Sequence, IteratorProtocol { | |
var iterators: [AnyIterator<Element>] | |
var lastElements: [Element?] | |
mutating func next() -> Element? { | |
var smallest: Element? = nil | |
var smallestIndex : Int? = nil | |
for index in lastElements.indices { | |
guard let element = lastElements[index] else { continue } | |
if (smallest == nil || element < smallest!) { |
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
protocol Counted { | |
associatedtype More : Counted | |
associatedtype Less : Counted where Self.More.Less == Self | |
} | |
struct CountedArray<T, C: Counted> { | |
var array: [T] | |
init(array: [T] = []) { | |
self.array = array |
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
public protocol Thing { | |
associatedtype T | |
func work() throws -> T | |
} | |
public struct AnyThing<T> : Thing { | |
let doWork: () throws -> T | |
public func work() throws -> T { | |
return try doWork() | |
} |
NewerOlder