Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Person {
- func compose(getter: SignalProducer<StoreItem, StoreError>,
- withNext next: SignalProducer<StoreItem, StoreError>,
- cashInHand: Double) -> SignalProducer<StoreItem, StoreError> {
- return getter
- .flatMapError { _ in next }
- .flatMap(.latest) { item -> SignalProducer<StoreItem, StoreError> in
- if item.price <= cashInHand { return SignalProducer(value: item) }
- return next
- }
- }
- }
- class Ted: Person {
- func searchForFood(at store: Store, cashInHand: Double) -> SignalProducer<StoreItem, FoodSearchError> {
- var getter = store.getItem(named: "Ceasar Sallad")
- getter = compose(getter: getter, withNext: store.getItem(named: "Tomato and Basil soup"), cashInHand: cashInHand)
- getter = compose(getter: getter, withNext: store.getItem(named: "Lots of Peanuts"), cashInHand: cashInHand)
- return getter.mapError { _ in .willStarve }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement