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
protocol BodyParameters { } | |
struct JSONBodyParameters: BodyParameters { } | |
struct MultipartFormDataBodyParameters: BodyParameters { } | |
protocol Request { | |
var bodyParameters: BodyParameters? { get } | |
} | |
extension Request { | |
var bodyParameters: BodyParameters? { |
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
typealias Contravariant<A> = (A) -> () | |
class Hoge { } | |
class Fuga: Hoge { } | |
let fuga: Fuga = Fuga() | |
let hoge: Hoge = Hoge() | |
let fugaC: Contravariant<Fuga> = { _ in } | |
let hogeC: Contravariant<Hoge> = { _ in } |
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
struct Prism<S, A> { | |
private let getOption: (S) -> A? | |
private let reverseGet: (A) -> S | |
init(getOption: @escaping (S) -> A?, reverseGet: @escaping (A) -> S) { | |
self.getOption = getOption | |
self.reverseGet = reverseGet | |
} | |
} |
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
struct Lens<S, A> { | |
typealias Getter = (S) -> A | |
typealias Setter = (S, A) -> S | |
fileprivate let _get: Getter | |
fileprivate let _set: Setter | |
init(get: @escaping Getter, set: @escaping Setter) { | |
self._get = get | |
self._set = set |
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 final class _TO { | |
lazy var DO: Never = { fatalError() }() | |
} | |
public let TO = _TO() |
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
func fatalErrorT<T>() -> T { | |
fatalError() | |
} | |
func fatalErrorT<T>(_ message: String) -> T { | |
fatalError(message) | |
} |
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
enum Error: Swift.Error { | |
case castError | |
} | |
func toInt(_ string: String) throws -> Int { | |
guard let i = Int(string) else { | |
throw Error.castError | |
} | |
return i | |
} |
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
enum Either<L, R> { | |
case left(L) | |
case right(R) | |
} | |
extension Either { | |
var rightProjection: RightProjection<L, R> { | |
return RightProjection(either: self) | |
} |
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
protocol HList { | |
associatedtype Head | |
associatedtype Tail | |
} | |
struct HCons<H, T: HList>: HList { | |
typealias Head = H | |
typealias Tail = T | |
let head: H |
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
func map2<A, B, C>(_ fa: Optional<A>, _ fb: Optional<B>, _ f: (A, B) -> C) -> Optional<C> { | |
switch (fa, fb) { | |
case (.some(let a), .some(let b)): // ここできると思わなかった... | |
return .some(f(a, b)) | |
default: | |
return .none | |
} | |
} |