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 Advent | |
import Algorithms | |
import Foundation | |
public enum Day10: Day { | |
public static let title = "Syntax Scoring" | |
public static func part1(_ input: Input) throws -> 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
import SwiftUI | |
// MARK: - SwiftUI environment definition (CoreTracking) | |
private struct EmptyTracker: Tracker { | |
func track(_ event: Event) {} | |
} | |
public struct TrackerEnvironmentKey: EnvironmentKey { |
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 enum Either<Left, Right> { | |
case left(Left) | |
case right(Right) | |
} | |
extension Either { | |
public func `as`(_ type: Left.Type) -> Left? { | |
guard case let .left(left) = self else { return nil } | |
return left |
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
// EXAMPLE | |
let string: String? = "Hello World" // String? | |
let unwrappedString = string.really.srsly.itsfine.honestly.aaarggh // String | |
print(unwrappedString) | |
// IMPLEMENTATION | |
extension Optional { |
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 Intersperse: Collection where Base: Collection { | |
public struct Index: Comparable { | |
enum Representation { | |
case end | |
case element(Base.Index) | |
case separator(Base.Index) | |
} | |
let representation: Representation |
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 SwiftUI | |
extension Binding { | |
func invmap<NewValue>( | |
to: @escaping (Value) -> NewValue, | |
from: @escaping (NewValue) -> Value | |
) -> Binding<NewValue> { | |
Binding<NewValue>( |
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 Multimap<Key: Hashable, Value: Hashable> { | |
fileprivate struct _Element: Hashable { | |
let key: Key | |
let value: Value | |
} | |
private var elements: Set<_Element> = [] |
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
@propertyWrapper | |
struct B { | |
var wrappedValue: Int | |
} | |
@propertyWrapper | |
struct Clamp { | |
var wrappedValue: 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
import SwiftUI | |
public struct UnwrapView<Some: View, None: View>: View { | |
private let some: () -> Some? | |
private let none: () -> None? | |
public init<Value>(value: Value?, | |
some: @escaping (Value) -> Some, |
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 Foundation | |
// MARK:- Usage | |
extension UserDefaults.Key where Value == Bool { | |
static let shouldDoSomething = Self(name: "shouldDoSomething", default: false) | |
} | |
struct View { |
NewerOlder