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.
(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.
(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.
(flatmap f collection)
Applies f to every element in collection, and then
concatenates the results (presumably a nested
collection) into a single flattened collection.
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 #)
(flatmap f future)
Applies f to the element eventually yielded by
future, then flattens the result (presumably a
nested future) a single flattened future.