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
prefix operator == | |
public prefix func == <T: Equatable>(value: T) -> (T) -> Bool { | |
return { | |
value == $0 | |
} | |
} |
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 Combine | |
import Foundation | |
class Actor<Message, State> { | |
@Published public private(set) var state: State | |
private var cancellables: Set<AnyCancellable> | |
let inbox = PassthroughSubject<Message, Never>() | |
init(initialState: State) { | |
state = initialState |
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
/** | |
Middleware is a structure that allows you to modify, filter out and dispatch more | |
actions, before the action being handled reaches the store. | |
*/ | |
public struct Middleware<State, Action> { | |
typealias Transform = (State, Action) -> [Action] | |
internal let transform: (State, Action) -> [Action] | |
/// Create a blank slate Middleware. | |
public init() { |
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 extension Bool { | |
func `if`<T>(true truth: @autoclosure () -> T, false falsity: @autoclosure () -> T) -> T { | |
switch self { | |
case true: | |
return truth() | |
case false: | |
return falsity() | |
} | |
} |
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 extension LazySequence { | |
/// Create an infinitely repeating sequence of values identical to `value`. | |
/// | |
/// let names = ["Jane", "Jack", "Gwynne", "Micky"] | |
/// let hellos = LazySequence(repeating: "Hello") | |
/// let g = zip(hellos, names).map { "\($0), \($1)" } | |
/// g == ["Hello, Jane", "Hello, Jack", "Hello, Gwynne", "Hello, Micky"] | |
/// | |
/// - Parameter repeating: `repeating` takes the element to be repeated. | |
/// - Returns: An infinite lazy sequence of `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
extension Optional { | |
func filter(_ isIncluded: (Wrapped) throws -> Bool) rethrows -> Optional<Wrapped> { | |
switch self { | |
case let value? where try isIncluded(value): | |
return value | |
default: | |
return nil | |
} | |
} | |
} |
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 RingBuffer<Element> { | |
public let capacity: Int | |
private var underlying: [Element] = [] | |
private var index: Int = 0 | |
public init(capacity: Int, initial: [Element] = []) { | |
precondition(capacity > 0, "A positive capacity is required") | |
underlying = Array(initial.suffix(capacity)) | |
self.capacity = capacity | |
index = underlying.count % capacity |
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 extension Collection { | |
/// Allows lensing properties before comparison by the std lib `firstIndex(where:)` function, using the `where` closure. | |
func firstIndex<T>(lensing path: KeyPath<Element, T>, where predicate: (T) -> Bool) -> Index? { | |
return firstIndex { | |
predicate($0[keyPath: path]) | |
} | |
} | |
} | |
public extension Collection { |
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 | |
public indirect enum JSON: Equatable { | |
case null | |
case string(String) | |
case number(String) | |
case bool(Bool) | |
case dictionary([String: JSON]) | |
case array([JSON]) | |
} |
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
// | |
// CTJSON.c | |
// CTObject | |
// | |
// Created by Charlotte Tortorella on 24/10/13. | |
// Copyright (c) 2013 Charlotte Tortorella. All rights reserved. | |
// | |
#include "CTJSON.h" | |
#include "CTFunctions.h" |
NewerOlder