Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Parallel Universes - Reader and Coreader for Swift DI

Elmar Kretzer
September 30, 2017

Parallel Universes - Reader and Coreader for Swift DI

Slides are from my talk at Functional Swift Conference 2017 in Berlin. http://www.funswiftconf.com

Elmar Kretzer

September 30, 2017
Tweet

More Decks by Elmar Kretzer

Other Decks in Programming

Transcript

  1. Parallel Universes Reader & Coreader for Dependency Injection Ì INCL.

    COMONADS, MONADS & THE DISTANT PAST Elmar Kretzer @elmkretzer
  2. - talk to network - use Date() - persist data

    Does your app even: - you name it Why care?
  3. http://hackage.haskell.org/package/mtl-1.1.0.2/docs/Control-Monad-Reader.html „Represents a computation, which can read values from a

    shared environment, pass values from function to function, and execute sub-computations in a modified environment.“ 1/2 READER MONAD
  4. very abstract return sth. based on sth. else afterwards pass

    it on to get sth. that itself returns sth. based on sth. else
  5. Describe dependent operations. Provide How at the end. 100 +

    10 + 5 + 2 100 * 10 * 5 * 2 100 - 10 - 5 - 2 100 / 10 / 5 / 2
  6. „In more technical language the Reader comonad is left adjoint

    to the Reader monad.“ 2/2 READER COMONAD https://hackage.haskell.org/package/category-extras-0.53.0/docs/Control-Comonad-Reader.html
  7. very co-abstract hold sth. and sth. else afterwards get sth.

    new from sth. and sth. else and return the new with sth. else
  8. Describe dependent access. Provide from WHAT at the end. RealWorld

    -> Api -> Server -> Time MockWorld - > Api -> Server -> Time
  9. Reader vs Coreader Comonad extend M a -> M a

    -> b -> M b Produce -> Consume Cokleisli Monad flatMap M a -> a -> M b -> M b Consume -> Produce Kleisli
  10. Coreader No. B/C Controller, Storyboards and so forth. Reader Yes.

    No one is holding you back. Worth it & simple to use in iOS?
  11. What do you do? Corridor
 µFramework for a Coreader-like 


    access to dependencies. Combined with Reader: full-fledged control. github.com/symentis/Corridor
  12. Pro? Unified Handling of DI. No business code for passing

    on Dependencies. Dependencies are transparent. Testing simply takes different Environments. Less code. More safety.