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
# Loan allocation coding challenge | |
A requirement of the Funding Circle marketplace is to *fairly* allocate loans to investors, according to certain investor-specific criteria. | |
In this coding challenge you are required to write code that takes a loan as input and allocates it to an investor. | |
## Challenge data | |
**Loans** have the following attributes: |
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
Mock Backend | |
Create a simple mock API using: | |
Simulate endpoints for: | |
GET /managers - Returns all managers and their assigned tasks. | |
POST /tasks - Adds a new task and triggers task assignment logic. |
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 handleError<Value>(publisher: PublisherResponse<BorrowerDetailsResponse, NetworkError>, | |
to keyPath: ReferenceWritableKeyPath<Self, Value>, | |
value: Value) { | |
publisher.sink(receiveCompletion: { [weak self] completion in | |
if case let .failure(error) = completion { | |
self?[keyPath: keyPath] = value | |
print(error) | |
} | |
}) { (response) 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
typealias SubscriberResponse<CustomError: Swift.Error> = Subscribers.Completion<CustomError> | |
typealias CompletionHandler<CustomError: Swift.Error> = (SubscriberResponse<CustomError>) -> Void | |
protocol MappableViewModel: class { | |
associatedtype CustomError: Swift.Error | |
var cancellables: Set<AnyCancellable> { get set } | |
func bind<Value>(_ publisher: AnyPublisher<Value, Never>, | |
to keyPath: ReferenceWritableKeyPath<Self, Value>) |
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 PublisherResponse<Value, CustomError: Swift.Error> = Publishers.Share<Publishers.ReceiveOn<AnyPublisher<Value, CustomError>, DispatchQueue>> | |
protocol MappableViewModel: class { | |
associatedtype CustomError: Swift.Error | |
var cancellables: Set<AnyCancellable> { get set } | |
func bind<Value>(_ publisher: AnyPublisher<Value, Never>, | |
to keyPath: ReferenceWritableKeyPath<Self, Value>) | |
func createPropertyPublisher<Value>(publisher: PublisherResponse<Value, CustomError>) -> AnyPublisher<Value, Never> | |
} |
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 MappableViewModel: class { | |
var cancellables: Set<AnyCancellable> { get set } | |
func bind<Value>(_ publisher: AnyPublisher<Value, Never>, | |
to keyPath: ReferenceWritableKeyPath<Self, Value>) | |
} | |
extension MappableViewModel { | |
func bind<Value>(_ publisher: AnyPublisher<Value, Never>, | |
to keyPath: ReferenceWritableKeyPath<Self, Value>) { |