Save 37% off PRO during our Black Friday Sale! »

DIY your own Combine framework

0392d75d394675d066e702a2f268302c?s=47 Li-Heng Hsu
September 22, 2019

DIY your own Combine framework

0392d75d394675d066e702a2f268302c?s=128

Li-Heng Hsu

September 22, 2019
Tweet

Transcript

  1. DIY your own Combine framework Basic Functional Reactive Programming concepts

    Li-Heng Hsu 許立衡 @ iPlayground 2019
  2. – Apple documentation "The Combine framework provides a declarative Swift

    API for processing values over time."
  3. None
  4. Concepts • Builder pattern • map(_:) method

  5. Builder pattern • For constructing instances • Like initializer, factory

    method… 1. Create a builder struct 2. Store construction info in it 3. Call its build() method to construct a product
  6. URLComponents URL builder

  7. Combine Subscription builder

  8. Builder pattern Combine Builder Publisher Construction info Operator build() Subscriber

    Product Subscription Roles
  9. CombineDIY.swift

  10. map(_:) method • There are different worlds in code •

    World of Uncertainty, World of Plurality, World of Erroneous... • Instances in these worlds can't be manipulated normally
  11. Optional World of Uncertainty

  12. World of Uncertainty Cat? (Cat) -> Double (Cat?) -> Double?

    map(_:)
  13. None
  14. Imperative Functional Metaphor Unwrap values Stack operations Optional if let

    x = x { /* ... */ } x.map { x in /* ... */ } Collection for i in x { /* ... */ } x.forEach { i in /* ... */ } Result if case .success(let x) = result { /* ... */ } result.map { x in /* ... */ }
  15. World of Plurality [Cat] (Cat) -> Double ([Cat]) -> [Double]

    map(_:)
  16. World of Temporality Publisher<Cat> (Cat) -> Double (Publisher<Cat>) ->
 Publisher<Double>

    map(_:)
  17. DIY map(_:)

  18. Feedback Come find me! Twitter: @lihenghsu