specs2 - lamdbajam 2014
TRANSCRIPT
Epic Success V Failure ? Refactoring to real FP
Eric Torreborre
Why, oh why?
What now?
How hard can it be?
HelloWorldSpec.scala
How hard can it be?
TextText
ExampleExample
TextText
TextText
ExampleExample
StepStep
ExampleExample
Filterin
gFilterin
gby
nameby
nameby
previousby
previous
Executio
nExecutio
nconcurre
ntconcurre
ntcondition
alcondition
al
ReportingReporting
consoleconsole
htmlhtml
How hard can it be?
Configuration(s)Configuration(s)ResourcesResources
FileSystemFileSystem
“Flow”“Flow”
StateState
CompositionComposition
ErrorsErrors
Problem?
Strategy
Strategy
Filtering by name
Filtering by previous
TextText ExampleExample ExampleExample TextText
StatsStats
resultresult
resultresultresultresult
resultresultresultresult
Monad stacks
Task[A]Task[A]
AA
ErrorError
AA
ErrorError
AA
FutureFuture
Monad stacks values
AAErrorError
FutureFuture
now(a: A)
delay(a: =>A)AA
ErrorError
FutureFuture
AAErrorError
FutureFuture
fail(t: Throwable)
and
flatM
ap!
and
flatM
ap!
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)
Action in action
Action opportunity
Read
everything
!
Read
everything
!
Filtering by previous
TextText ExampleExample ExampleExample TextText
StatsStats
resultresult
resultresultresultresult
resultresultresultresult
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
Filtering by previous
flatM
ap!
flatM
ap!
Filtering by previous
On stacks
No big
dealNo big
deal
SpecialiseSpecialise
LibraryLibrary
Composition?Composition?
Integration?Integration?
Scalaz-stream
Concurrency with
Easy!Easy!
Concurrency with
With
state!With
state!
TextText ExampleExample ExampleExample StepStep ExampleExample
stop herestop here
Flatmap with
Online
testing!Online
testing!
Flatmap with
Online
testing!Online
testing!
Text1Text1 Example1Example1 Example2Example2 Example3Example3
Text1Text1 Example1Example1 Example2Example2 Example3Example3
Example2.1Example2.1 Example2.2Example2.2
Reporting with
“duplicate”stream
“duplicate”stream
Write to consoleWrite to console
Accumulatestate
Accumulatestate
Reporting with
Text1Text1 Example1Example1 Example2Example2 Example3Example3
“t1”“t1” “e1”“e1” “e2”“e2” “e3”“e3”
> Console
statsstats statsstats statsstats
Reporting with
Not composable
Not composable
Reporting with and Folds!
Reporting with and Folds!
Reporting with and Folds!
Opaque
dependent
type
Opaque
dependent
type
Reporting with and Folds!
Fold Monoid!Fold Monoid!
Reporting with and Folds!
Conclusion