SHARE
TWEET

Untitled

a guest Mar 18th, 2019 44 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Person {
  2.     func compose(getter: SignalProducer<StoreItem, StoreError>,
  3.                  withNext next: SignalProducer<StoreItem, StoreError>,
  4.                  cashInHand: Double) -> SignalProducer<StoreItem, StoreError> {
  5.         return getter
  6.             .flatMapError { _ in next }
  7.             .flatMap(.latest) { item -> SignalProducer<StoreItem, StoreError> in
  8.                 if item.price <= cashInHand { return SignalProducer(value: item) }
  9.                 return next
  10.             }
  11.     }
  12. }
  13.  
  14. class Ted: Person {
  15.     func searchForFood(at store: Store, cashInHand: Double) -> SignalProducer<StoreItem, FoodSearchError> {
  16.         var getter = store.getItem(named: "Ceasar Sallad")
  17.         getter = compose(getter: getter, withNext: store.getItem(named: "Tomato and Basil soup"), cashInHand: cashInHand)
  18.         getter = compose(getter: getter, withNext: store.getItem(named: "Lots of Peanuts"), cashInHand: cashInHand)
  19.        
  20.         return getter.mapError { _ in .willStarve }
  21.     }
  22. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top