Slide 1

Slide 1 text

The power of small abstractions. () = ?

Slide 2

Slide 2 text

Txus. /t∫us/

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

Abstraction. By Smok Bazyli (Own work) [CC BY-SA 3.0 (http://creativecommons.org/licenses/by-sa/3.0)], via Wikimedia Commons Image taken by Robert Southworth, 2004-9-4.

Slide 6

Slide 6 text

Abstraction.

Slide 7

Slide 7 text

“I suspect, nonetheless, that he wasn’t much capable of thinking. To think is to forget differences, to generalise, to abstract.” Jorge Luis Borges

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

1 + 1 2 =

Slide 11

Slide 11 text

“hello” + “world” “helloworld” =

Slide 12

Slide 12 text

[1,2] + [3,4] [1,2,3,4] =

Slide 13

Slide 13 text

+ =

Slide 14

Slide 14 text

1 + (1 + 1) (1 + 1) + 1 =

Slide 15

Slide 15 text

“a” + (“b” + “c”) (“a” + “b”) + “c” =

Slide 16

Slide 16 text

[1] + ([2] + [3]) ([1] + [2]) + [3] =

Slide 17

Slide 17 text

+ ( + ) = ( + ) +

Slide 18

Slide 18 text

0

Slide 19

Slide 19 text

1 + 0 1 =

Slide 20

Slide 20 text

“hello” + “” “hello” =

Slide 21

Slide 21 text

[1,2] + [] [1,2] =

Slide 22

Slide 22 text

+ =

Slide 23

Slide 23 text

+ ( + )

Slide 24

Slide 24 text

(foldl + 0 [1,2,3]) 6 =

Slide 25

Slide 25 text

(foldl + “” [“a”,”b”,”c”]) “abc” =

Slide 26

Slide 26 text

(foldl + [] [[1],[2],[3]]) [1,2,3] =

Slide 27

Slide 27 text

(foldl + [ , , ]) =

Slide 28

Slide 28 text

…functions?

Slide 29

Slide 29 text

( + )() (()) =

Slide 30

Slide 30 text

+ ( + ℎ) ( + ) + ℎ =

Slide 31

Slide 31 text

() =

Slide 32

Slide 32 text

+ =

Slide 33

Slide 33 text

(foldl + [,,ℎ])() = ((ℎ()))

Slide 34

Slide 34 text

+ ( + )

Slide 35

Slide 35 text

Monoids.

Slide 36

Slide 36 text

No content

Slide 37

Slide 37 text

[ Arrays ] ( Lists ) { Sets }

Slide 38

Slide 38 text

[ Arrays ] ( Lists ) { Sets } Collection[T]

Slide 39

Slide 39 text

0 | n

Slide 40

Slide 40 text

(map f collection) Applies f to each element of in collection, if any. Returns a collection with the transformed elements, or an empty one if the original was empty.

Slide 41

Slide 41 text

(map inc [1,2,3]) (map inc []) [2,3,4] []

Slide 42

Slide 42 text

Some(t) None()

Slide 43

Slide 43 text

Some(t) None() Option[T]

Slide 44

Slide 44 text

0 | 1

Slide 45

Slide 45 text

(map f option) Applies f to the only element in option, if it’s there. Returns an option containing the transformed element or None.

Slide 46

Slide 46 text

(map inc (some 1)) (some 2) (map inc (none)) (none)

Slide 47

Slide 47 text

Future[T]

Slide 48

Slide 48 text

eventually x?

Slide 49

Slide 49 text

(map f future) Applies f to the element that the future may eventually yield, if it ever does. Returns a future that’ll yield either the transformed element or an error.

Slide 50

Slide 50 text

(map inc (future 1)) (future 2) (map inc (future error)) (future error)

Slide 51

Slide 51 text

No content

Slide 52

Slide 52 text

Box[T]

Slide 53

Slide 53 text

(map f ) Applies f to whatever is inside in the way sees fit. Returns the result in the same kind of .

Slide 54

Slide 54 text

IN THE WAY IT SEES FIT.

Slide 55

Slide 55 text

HOW MANY TIMES.

Slide 56

Slide 56 text

EXACTLY WHEN.

Slide 57

Slide 57 text

IF AT ALL. ?

Slide 58

Slide 58 text

Encapsulation.

Slide 59

Slide 59 text

(first []) (value (none)) Don’t reach into the box. (await (future (sleep)) nil? error? nil? error? blocks thread!

Slide 60

Slide 60 text

Let the decide.

Slide 61

Slide 61 text

Let the decide. Functors.

Slide 62

Slide 62 text

[+] [1, 2, 3] [2, 3, 4] [1, 1, 1]

Slide 63

Slide 63 text

(some +) (some 1) (some 2) (some 1)

Slide 64

Slide 64 text

(fapply …) Applies whatever function is inside taking each _ as arguments, assuming they are all the same kind of box, in the way the boxes see fit. f f

Slide 65

Slide 65 text

(fapply Applies whatever function is inside _ as arguments, assuming they are all the same kind of box, in the way the boxes see fit. f f Applicative functors.

Slide 66

Slide 66 text

No content

Slide 67

Slide 67 text

Composition.

Slide 68

Slide 68 text

Box[T] (T -> Box[U])

Slide 69

Slide 69 text

Collection[String] (String -> Collection[String])

Slide 70

Slide 70 text

“foo.bar,foo.baz,foo.quux” (split “,”) [“foo.bar”,”foo.baz”,”foo.quux”] (map #(split “.” %)) [[“foo”, “bar”], [”foo”, “baz”], [”foo”, “quux”]]

Slide 71

Slide 71 text

(flatmap f collection) Applies f to every element in collection, and then concatenates the results (presumably a nested collection) into a single flattened collection.

Slide 72

Slide 72 text

“foo.bar,foo.baz,foo.quux” (split “,”) [“foo.bar”,”foo.baz”,”foo.quux”] (flatmap #(split “.”)) [“foo”, “bar”, ”foo”, “baz”, ”foo”, “quux”]

Slide 73

Slide 73 text

Option[Address] (Address -> Option[StreetNumber])

Slide 74

Slide 74 text

user (address) (some #
) (map street-number) (some (some #))

Slide 75

Slide 75 text

(flatmap f optional) Applies f to the element in optional if it’s there, then flattens the result (presumably a nested optional) a single flattened optional.

Slide 76

Slide 76 text

user (address) (some #
) (flatmap street-number) (some #)

Slide 77

Slide 77 text

Future[Repo] (Repo -> Future[Followers])

Slide 78

Slide 78 text

github-user (first-repo) (future repo1) (map followers) (future (future [follower1, follower2, …]))

Slide 79

Slide 79 text

(flatmap f future) Applies f to the element eventually yielded by future, then flattens the result (presumably a nested future) a single flattened future.

Slide 80

Slide 80 text

github-user (first-repo) (future repo1) (flatmap followers) (future [follower1, follower2, …])

Slide 81

Slide 81 text

Box[T] (T -> Box[U]) (U -> Box[V]) (V -> Box[X]) …

Slide 82

Slide 82 text

Applies f to whatever is inside in the way sees fit, then flattens the result (presumably a nested ) into a single flat of the same kind. (flatmap f )

Slide 83

Slide 83 text

Box[T] (T -> Box[U]) (U -> Box[V]) (V -> Box[X]) … Monads.

Slide 84

Slide 84 text

No content

Slide 85

Slide 85 text

+ ( + ) foldl

Slide 86

Slide 86 text

map

Slide 87

Slide 87 text

fapply f …

Slide 88

Slide 88 text

flatmap

Slide 89

Slide 89 text

No content

Slide 90

Slide 90 text

(and shout out to Jessica Kerr! @jessitron) Thank you. txustice txus Questions?