Skip to content
Snippets Groups Projects
Commit f8547499 authored by Dariusz Rybicki's avatar Dariusz Rybicki
Browse files

Add ConnectionGetId functor

parent a5211798
No related branches found
No related tags found
2 merge requests!102Release 1.0.0,!18Update Bindings
This commit is part of merge request !18. Comments created here will be created in the context of that merge request.
import Bindings import Bindings
public struct Connection { public struct Connection {
// TODO: public var getId: ConnectionGetId
} }
extension Connection { extension Connection {
public static func live(_ bindingsConnection: BindingsConnection) -> Connection { public static func live(_ bindingsConnection: BindingsConnection) -> Connection {
Connection() Connection(
getId: .live(bindingsConnection)
)
} }
public static func live(_ bindingsConnection: BindingsAuthenticatedConnection) -> Connection { public static func live(_ bindingsConnection: BindingsAuthenticatedConnection) -> Connection {
Connection() Connection(
getId: .live(bindingsConnection)
)
} }
} }
extension Connection { extension Connection {
public static let unimplemented = Connection() public static let unimplemented = Connection(
getId: .unimplemented
)
} }
import Bindings
import XCTestDynamicOverlay
public struct ConnectionGetId {
public var run: () -> Int
public func callAsFunction() -> Int {
run()
}
}
extension ConnectionGetId {
public static func live(_ bindingsConnection: BindingsConnection) -> ConnectionGetId {
ConnectionGetId(run: bindingsConnection.getId)
}
public static func live(_ bindingsConnection: BindingsAuthenticatedConnection) -> ConnectionGetId {
ConnectionGetId(run: bindingsConnection.getId)
}
}
extension ConnectionGetId {
public static let unimplemented = ConnectionGetId(
run: XCTUnimplemented("\(Self.self)")
)
}
import Bindings
public struct ConnectionIdProvider {
public var get: () -> Int
public func callAsFunction() -> Int {
get()
}
}
extension ConnectionIdProvider {
public static func live(
bindingsConnection: BindingsConnection
) -> ConnectionIdProvider {
ConnectionIdProvider(get: bindingsConnection.getId)
}
public static func live(
bindingsAuthenticatedConnection: BindingsAuthenticatedConnection
) -> ConnectionIdProvider {
ConnectionIdProvider(get: bindingsAuthenticatedConnection.getId)
}
}
#if DEBUG
extension ConnectionIdProvider {
public static let failing = ConnectionIdProvider {
fatalError("Not implemented")
}
}
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment