Specs2

36
Go functional!

description

The slides for the fp-syd presentation: http://www.youtube.com/watch?v=lMyNRUuEvNU. Sorry for the bad fonts which have been converted by SlideShare on upload.

Transcript of Specs2

Page 1: Specs2

Go functional!

Page 2: Specs2

Shame

Page 3: Specs2

Mutability

Page 4: Specs2

Concurrency

Page 5: Specs2

Acceptance

Page 6: Specs2

Why

The idea

User

DesignProgram

Page 7: Specs2

Go Functional!

But what

is it?!

Page 8: Specs2

Referential transparency

Immutabili

ty

Page 9: Specs2

behavior

pipelined

FPemerg

entbehavior

Processing data structures

OO

Page 10: Specs2

Why

The idea

User

DesignProgram

Page 11: Specs2

Starting point

Page 12: Specs2

Nesting

Precedence:+!^

Page 13: Specs2

FormattingText

Example

Text

Example

Example

Page 14: Specs2

Formatting

pbrendt, t(i)bt, bt(i)

acceptance

Page 15: Specs2

Context

Page 16: Specs2

doBefore

withDb.apply(e2)

Page 17: Specs2

Why

The idea

User

DesignProgram

Page 18: Specs2

Run

execute

levels

select

sequence

arguments

statistics

to text

to html

Page 19: Specs2

Laziness vs evaluation

Page 20: Specs2

Iterating

Page 21: Specs2

Traverse

A datastructure to

traversethe

accumulation

the mapping

Page 22: Specs2

Applicative magic?

Lots of instances:• State• List• Monad• Monoid

simple

composable Type inference is hard,Let’s go

shopping!

Page 23: Specs2

Reduceraggregation

“parallel” composition

mapping

specs2 reducers:• Levels• Statistics• Arguments• Text• Html

Page 24: Specs2

Why

The idea

User

DesignProgram

Page 25: Specs2

Trees

Text

Example 1

Example 2

SuiteDescript

ion

Test Descriptio

n 1

Test Descriptio

n 2

SuiteDescription

fChildren = TD1, TD2

Page 26: Specs2

TreeLoc

Page 27: Specs2

TreeLoc

<h1/>

<h2/> <h2/>

<body>

<h2>part 1</h2><h2>part 2</h2>

<h1>Title 1</h1>

</body>

Anti-XMLThe non-violent solution

Page 28: Specs2

Concurrency

a concurrent task

=> Promise[Seq[ExecutedFragment]]

Page 29: Specs2

Exceptions

Page 30: Specs2

Exceptions

Page 31: Specs2

Exceptions

Page 32: Specs2

Mocks

<h1/>

Page 33: Specs2

MutabilityBack fo

r

good

Nothing here!

Throws exception

Page 34: Specs2

ConfigurationPart of the flow

named parameters + defaults

nested ‘record’

Page 35: Specs2

ConfigurationImplicits

implicit arguments

default value

Page 36: Specs2

Conclusion

• Reliability• Concurrency• Composition• Less mocks• val/vars

• DSL• Type inference• Learning curve