Top Banner
Epic Success V Failure ? Refactoring to real FP Eric Torreborre
35

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

Aug 27, 2014

Download

Software

Eric Torreborre

My presentation at LambdaJam 2014
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Epic success \/ failure, refactoring to *real* FP

Epic Success V Failure ? Refactoring to real FP

Eric Torreborre

Page 2: Epic success \/ failure, refactoring to *real* FP

Why, oh why?

Page 3: Epic success \/ failure, refactoring to *real* FP

What now?

Page 4: Epic success \/ failure, refactoring to *real* FP

How hard can it be?

HelloWorldSpec.scala

Page 5: Epic success \/ failure, refactoring to *real* FP

How hard can it be?

Text

Example

Text

Text

Example

Step

Example

Filtering

by nameby previous

Execution

concurre

ntcondition

al

Reporting

console

html

Page 6: Epic success \/ failure, refactoring to *real* FP

How hard can it be?

Configuration(s)Resources

FileSystem

“Flow”

State

Composition

Errors

Page 7: Epic success \/ failure, refactoring to *real* FP

Problem?

Page 8: Epic success \/ failure, refactoring to *real* FP

Strategy

Page 9: Epic success \/ failure, refactoring to *real* FP

Strategy

Page 10: Epic success \/ failure, refactoring to *real* FP

Filtering by name

Page 11: Epic success \/ failure, refactoring to *real* FP

Filtering by previous

Text Example Example Text

Stats

result

resultresult

resultresult

Page 12: Epic success \/ failure, refactoring to *real* FP

Monad stacks

Task[A]

AError

AError

A

Future

Page 13: Epic success \/ failure, refactoring to *real* FP

Monad stacks values

AError

Future

now(a: A)

delay(a: =>A)A

Error

Future

AError

Future

fail(t: Throwable)

and

flatM

ap!

Page 14: Epic success \/ failure, refactoring to *real* FP

Action in action

Action[A]

AError

AError

A

IO

AError

IO

Reader

Conf => IO[A] => IO[Error]

Error = String | Throwable | (String, Throwable)

Page 15: Epic success \/ failure, refactoring to *real* FP

Action in action

Page 16: Epic success \/ failure, refactoring to *real* FP

Action opportunity

Read

everything

!

Page 17: Epic success \/ failure, refactoring to *real* FP

Filtering by previous

Text Example Example Text

Stats

result

resultresult

resultresult

Page 18: Epic success \/ failure, refactoring to *real* FP

Filtering by previous

Text Example Example Text

Stats

result

Action[Fragment] => Task[Fragment]

Fragment => Action[Result]Action[Result] => Action[Fragment]

map

Task[Fragment] => Process[Task, Fragment]

eval

Page 19: Epic success \/ failure, refactoring to *real* FP

Filtering by previous

flatM

ap!

Page 20: Epic success \/ failure, refactoring to *real* FP

Filtering by previous

Page 21: Epic success \/ failure, refactoring to *real* FP

On stacks

No big deal

Specialise

Library

Composition?

Integration?

Page 22: Epic success \/ failure, refactoring to *real* FP

Scalaz-stream

Page 23: Epic success \/ failure, refactoring to *real* FP

Concurrency with

Easy!

Page 24: Epic success \/ failure, refactoring to *real* FP

Concurrency with

With state!

Text Example Example Step Example

stop here

Page 25: Epic success \/ failure, refactoring to *real* FP

Flatmap with

Online

testing!

Page 26: Epic success \/ failure, refactoring to *real* FP

Flatmap with

Online

testing!

Text1 Example1 Example2 Example3

Text1 Example1 Example2 Example3

Example2.1 Example2.2

Page 27: Epic success \/ failure, refactoring to *real* FP

Reporting with

“duplicate”stream

Write to console

Accumulatestate

Page 28: Epic success \/ failure, refactoring to *real* FP

Reporting with

Text1 Example1 Example2 Example3

“t1” “e1” “e2” “e3”

> Console

stats stats stats

Page 29: Epic success \/ failure, refactoring to *real* FP

Reporting with

Not composable

Page 30: Epic success \/ failure, refactoring to *real* FP

Reporting with and Folds!

Page 31: Epic success \/ failure, refactoring to *real* FP

Reporting with and Folds!

Page 32: Epic success \/ failure, refactoring to *real* FP

Reporting with and Folds!

Opaque

dependent

type

Page 33: Epic success \/ failure, refactoring to *real* FP

Reporting with and Folds!

Fold Monoid!

Page 34: Epic success \/ failure, refactoring to *real* FP

Reporting with and Folds!

Page 35: Epic success \/ failure, refactoring to *real* FP

Conclusion