Epic success \/ failure, refactoring to *real* FP


Published on

My presentation at LambdaJam 2014

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide
  • 3 years of specs1, 4 years of specs2
    Html output: I suck at html / javascript
    Open Source = find people! Clinton -> new design, new CSS
    But implementation: ugh…
    Simplification / Composition / extension
    What about being “pure”
  • Lots of possibilities
    More knowledge
    What happened: Success or Failure?
    This is eventually looking good and possibly looking fantastic
  • Simple structure:
    But complex execution model -> even not enough separation between declaration and run
    And several functionalities on top
    - by tag -> read command line
    - by previous -> read files
    - must respect steps!
    - must be fully concurrent
    - console must flow!
    - statistics must be stored
    Thread pool?
  • Interested by the Cake Pattern and the ability to “hide” the implementation + Daniel Spiewak presentation on parametrizing it with a Monad
    But how far can you go with small functions?
  • Use an elaborate data structure right away
  • Process[Task, T] is a stream of Ts produced by a Task
    Process1 is like a map or filter operation
    A Task is an Error/Future monad stack
  • Use a for comprehension
    Can be a bit tedious to retrofit the code like that
    But this is mostly a mechanical transformation
    And this provides a benefit
  • Liberally use the configuration to influence the behaviour of your programming
    That’s dependency injection!
  • Better than I feared
    In Scala you need to build a special stack for what you are doing, Reader Writer State won’t work easily
    Build your own collection of operators to create values, fromIO, failure,…
    Question : can you keep Configuration modular?
    Question: how to operate with another stack like Action <-> Task
  • Use an elaborate data structure right away
  • Not composable because the fragments are going to be executed twice 
  • Use a Fold to accumulate state
  • Stacks not too hard to use
    Streamz a very powerful model, but very recent library and might need to come up with Folds for additional composition
    Being Functional = Honest brings opportunities
    - inject anything anywhere
    - careful execution model + flatmap == better execution control
  • Epic success \/ failure, refactoring to *real* FP

    1. 1. Epic Success V Failure ? Refactoring to real FP Eric Torreborre
    2. 2. Why, oh why?
    3. 3. What now?
    4. 4. How hard can it be? HelloWorldSpec.scala
    5. 5. How hard can it be? TextText ExampleExample TextText TextText ExampleExample StepStep ExampleExample Filtering Filtering by name by name by previous by previous Execution Execution concurrent concurrent conditional conditional Reporting Reporting console console htmlhtml
    6. 6. How hard can it be? Configuration(s)Configuration(s)ResourcesResources FileSystemFileSystem “Flow”“Flow” StateState CompositionComposition ErrorsErrors
    7. 7. Problem?
    8. 8. Strategy
    9. 9. Strategy
    10. 10. Filtering by name
    11. 11. Filtering by previous TextText ExampleExample ExampleExample TextText StatsStats resultresult resultresultresultresult resultresultresultresult
    12. 12. Monad stacks Task[A]Task[A] AA ErrorError AA ErrorError AA FutureFuture
    13. 13. Monad stacks values AA ErrorError FutureFuture now(a: A) delay(a: =>A) AA ErrorError FutureFuture AA ErrorError FutureFuture fail(t: Throwable) and flatM ap! and flatM ap!
    14. 14. Action in action Action[A]Action[A] AA ErrorError AA ErrorError AA IOIO AA ErrorError IOIO ReaderReader Conf => IO[A] => IO[Error] Error = String | Throwable | (String, Throwable)
    15. 15. Action in action
    16. 16. Action opportunity Read everything!Read everything!
    17. 17. Filtering by previous TextText ExampleExample ExampleExample TextText StatsStats resultresult resultresultresultresult resultresultresultresult
    18. 18. Filtering by previous TextText ExampleExample ExampleExample TextText StatsStats resultresult Action[Fragment] => Task[Fragment] Fragment => Action[Result] Action[Result] => Action[Fragment] mapmap Task[Fragment] => Process[Task, Fragment] evaleval
    19. 19. Filtering by previous flatM ap! flatM ap!
    20. 20. Filtering by previous
    21. 21. On stacks No big deal No big deal Specialise Specialise LibraryLibrary Composition? Composition? Integration? Integration?
    22. 22. Scalaz-stream
    23. 23. Concurrency with Easy!Easy!
    24. 24. Concurrency with With state! With state! TextText ExampleExample ExampleExample StepStep ExampleExample stop herestop here
    25. 25. Flatmap with Online testing! Online testing!
    26. 26. Flatmap with Online testing! Online testing! Text1Text1 Example1Example1 Example2Example2 Example3Example3 Text1Text1 Example1Example1 Example2Example2 Example3Example3 Example2.1Example2.1 Example2.2Example2.2
    27. 27. Reporting with “duplicate” stream “duplicate” stream Write to console Write to console Accumulate state Accumulate state
    28. 28. Reporting with Text1Text1 Example1Example1 Example2Example2 Example3Example3 “t1”“t1” “e1”“e1” “e2”“e2” “e3”“e3” > Console statsstats statsstats statsstats
    29. 29. Reporting with Not composable  Not composable 
    30. 30. Reporting with and Folds!
    31. 31. Reporting with and Folds!
    32. 32. Reporting with and Folds! Opaque dependent typeOpaque dependent type
    33. 33. Reporting with and Folds! Fold Monoid! Fold Monoid!
    34. 34. Reporting with and Folds!
    35. 35. Conclusion