This file contains hidden or 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
#!/usr/bin/env sh | |
set -e | |
fancy_echo() { | |
local fmt="$1"; shift | |
printf "\n$fmt\n" "$@" | |
} |
This file contains hidden or 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 PermutationIterator<T>: IteratorProtocol { | |
private var hasReturnedInitial = false | |
private var a: [T] | |
private var c: [Int] | |
private let n: Int | |
private var i = 0 | |
public init<C: Collection>(_ values: C) where C.Element == T { | |
a = Array(values) | |
n = a.count |
This file contains hidden or 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 Collection { | |
func anySatisfy(_ p: (Element) -> Bool) -> Bool { | |
return !self.allSatisfy { !p($0) } | |
} | |
} |
This file contains hidden or 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
final class HelloWorldViewModel: ViewModelType { | |
let input: Input | |
let output: Output | |
struct Input { | |
let name: Anyobserver<String> | |
} | |
struct Output { | |
let greeting: Driver<String> |
This file contains hidden or 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
/// A type representing an alternative of one of two types. | |
/// | |
/// By convention, and where applicable, `Left` is used to indicate failure, while `Right` is used to indicate success. (Mnemonic: “right” is a synonym for “correct.”) | |
/// | |
/// Otherwise, it is implied that `Left` and `Right` are effectively unordered alternatives of equal standing. | |
public enum Either<Left, Right> { | |
case left(Left) | |
case right(Right) | |
/// Returns the value of `Left` instances, or `nil` for `Right` instances. |
This file contains hidden or 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
dispatchPrecondition( | |
condition: DispatchPredicate.onQueue(DispatchQueue.main) | |
) |
This file contains hidden or 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 Request where Response: Decodable { | |
func handle( | |
response: Result<Data, Error>, | |
completion: (Result<Response, Error>) -> Void) { | |
completion(Result { | |
try JSONDecoder().decode(Response.self, from: response.get()) | |
}) | |
} | |
} |
This file contains hidden or 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
/// A wrapper around a repeating timer that does not require invalidation. | |
final class Pendulum { | |
let timer: Timer | |
init(seconds: TimeInterval, closure: @escaping () -> ()) { | |
timer = Timer.scheduledTimer( | |
withTimeInterval: seconds, | |
repeats: true, | |
block: { _ in | |
closure(); |
This file contains hidden or 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
found_rbenv='' | |
rbenvdirs=("$HOME/.rbenv" "$HOME/.local/rbenv" "/usr/local/opt/rbenv" "/usr/local/rbenv" "/opt/rbenv") | |
for rbenvdir in "${rbenvdirs[@]}" ; do | |
if [ -z "$found_rbenv" ] && [ -d "$rbenvdir/versions" ]; then | |
found_rbenv=true | |
if [ -z "$RBENV_ROOT" ]; then | |
RBENV_ROOT=$rbenvdir | |
export RBENV_ROOT | |
fi |
This file contains hidden or 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 RxRelay | |
import RxSwift | |
@propertyWrapper | |
public struct BehaviorRelayWrapping<T> { | |
private let subject: BehaviorRelay<T> | |
// MARK: PropertyWrapper | |
public let wrappedValue: Observable<T> |