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 | |
import Service | |
#if os(Linux) | |
import Glibc | |
#else | |
import Darwin | |
#endif | |
extension Environment { |
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
/** | |
Make toolbar go to the left below 650px | |
*/ | |
@media screen and (max-width: 650px) { | |
.ui { | |
flex-direction: row!important; | |
} | |
.tabs-bar { | |
flex-direction: column!important; |
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 struct BoundedSequence<Base>: Sequence, IteratorProtocol where Base: Sequence { | |
public struct Boundary: Equatable { | |
public let isStart: Bool | |
public let isEnd: Bool | |
} | |
private var _iterator: Base.Iterator | |
private var _previous: Base.Element? | |
private var _current: Base.Element? | |
private var _next: Base.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
/// Withable is a simple protocol to make constructing | |
/// and modifying objects with multiple properties | |
/// more pleasant (functional, chainable, point-free) | |
public protocol Withable { | |
init() | |
} | |
public extension Withable { | |
/// Construct a new instance, setting an arbitrary subset of properties | |
init(with config: (inout Self) -> Void) { |
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
/*: | |
This is a concept re-implementation of the @Binding and @State property wrappers from SwiftUI | |
The only purpose of this code is to implement those wrappers myself | |
just to understand how they work internally and why they are needed, | |
⚠️ This is not supposed to be a reference implementation nor cover all | |
subtleties of the real Binding and State types. | |
The only purpose of this playground is to show how re-implementing | |
them myself has helped me understand the whole thing better |
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
// | |
// ContentView.swift | |
// Layout | |
// | |
// Created by Matt Gallagher on 7/6/19. | |
// Copyright © 2019 Matt Gallagher. All rights reserved. | |
// | |
import SwiftUI |
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 | |
import Combine | |
struct AdaptsToSoftwareKeyboard: ViewModifier { | |
@State var currentHeight: CGFloat = 0 | |
func body(content: Content) -> some View { | |
content | |
.padding(.bottom, currentHeight) | |
.edgesIgnoringSafeArea(.bottom) |
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
// In the Point-Free series on application architecture and state management, | |
// they define a series of ways to compose reducers. Sometimes, however, it seems | |
// that the signature of reducers can complicate the signature of these different | |
// compositions. I found creating a typealias for reducers separated the concern of | |
// understanding the concept of reducers and understanding their higher order | |
// constructions, especially when starting to write my own. | |
// Adding a typealias for Reducer can make certain parts a bit more readable | |
typealias Reducer<Value, Action> = (inout Value, Action) -> Void |
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 Publisher { | |
func cancellable<Id: Hashable>(id: Id) -> AnyPublisher<Output, Failure> { | |
return Deferred { () -> PassthroughSubject<Output, Failure> in | |
cancellables[id]?.cancel() | |
let subject = PassthroughSubject<Output, Failure>() | |
cancellables[id] = self.subscribe(subject) | |
return subject | |
} | |
.eraseToAnyPublisher() |
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 CustomMatcher<Value> { | |
let closure: (Value) -> Bool | |
static func ~= (caseValue: CustomMatcher<Value>, switchValue: Value) -> Bool { | |
caseValue.closure(switchValue) | |
} | |
static func ~= (caseValue: Value, switchValue: CustomMatcher<Value>) -> Bool { | |
switchValue.closure(caseValue) | |
} | |
} |