-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
451 lines (401 loc) · 17 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title>Pipe it, curry it, tacit!</title>
<link rel="stylesheet" href="dist/reset.css" />
<link rel="stylesheet" href="dist/reveal.css" />
<link rel="stylesheet" href="dist/theme/forest-dark.css" id="theme" />
<!-- Theme used for syntax highlighted code -->
<link rel="stylesheet" href="plugin/highlight/forest-dark.css" id="highlight-theme" />
<style>
:root {
--gradient: linear-gradient(120deg, var(--selection-background-color) 0%, var(--link-color) 100%);
}
cite {
display: inline-block;
font-size: 0.5em;
font-style: italic;
}
mark {
background-color: var(--selection-background-color);
}
mark > * {
color: var(--selection-color) !important;
}
.gradient-text {
background-image: var(--gradient);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
-moz-background-clip: text;
-moz-text-fill-color: transparent;
}
.gradient-bar {
width: 100%;
height: 5vmin;
background: var(--gradient);
transform: skewX(-30deg);
border-radius: 5px;
}
.gradient-arrow {
position: absolute;
top: 8vmin;
left: 0;
font-size: 10vmin;
transform: translateX(-50%);
opacity: 0;
text-shadow: 0 0 1vmin rgba(255, 255, 255, 0.5);
transition: all 600ms ease-in-out;
}
</style>
</head>
<body>
<div class="reveal">
<div class="slides">
<section>
<section
data-background-color="black"
data-background-image="assets/pipes.webp"
data-background-opacity="0.25"
>
<h1 class="gradient-text" style="text-align: left">
<span>Pipe it</span><br />
<span style="margin-left: 20%">curry it</span><br />
<span style="margin-left: 64%">tacit</span>
</h1>
<cite style="position: absolute; left: 0; bottom: 0; font-size: 1vmin; opacity: 0.5">
Photo by <a href="https://pixnio.com/objects/rusty-round-metal-pipes-stacked">Bicanski</a> on
<a href="https://pixnio.com/">Pixnio</a>
</cite>
</section>
<section>
<img src="assets/logo-frontmen.svg" style="height: 25vmin" />
<h3>
<img src="assets/avatar.svg" style="height: 8vmin; margin: 0; vertical-align: text-bottom" />
Abbe Keultjes
</h3>
<p>abbe.keultjes@frontmen.nl</p>
</section>
</section>
<section>
<section class="r-stretch">
<h3>More declarative</h3>
<div class="fragment" style="position: relative; margin-bottom: 10vmin">
<div style="display: flex; justify-content: space-between">
<span style="margin-bottom: 1rem">Imperative</span>
<span style="margin-bottom: 1rem">Declarative</span>
</div>
<div class="gradient-bar"></div>
<div class="gradient-arrow">⬆</div>
<!-- todo: reduce code duplication -->
<div class="fragment fade-in-then-out">
<div style="display: flex; justify-content: space-between">
<ul style="list-style: none; margin: 2rem 0 0">
<li>Concerned with <em>how</em></li>
</ul>
<ul style="list-style: none; margin: 2rem 0 0; text-align: right; width: 50%">
<li>Concerned with <em>what</em></li>
</ul>
</div>
</div>
<div class="fragment fade-in-then-out">
<div style="display: flex; justify-content: space-between">
<ul style="list-style: none; margin: 2rem 0 0">
<li>Concerned with <em>how</em></li>
<li>Implementation details</li>
</ul>
<ul style="list-style: none; margin: 2rem 0 0; text-align: right; width: 50%">
<li>Concerned with <em>what</em></li>
<li>Abstraction</li>
</ul>
</div>
</div>
<div class="fragment fade-in-then-out">
<div style="display: flex; justify-content: space-between">
<ul style="list-style: none; margin: 2rem 0 0">
<li>Concerned with <em>how</em></li>
<li>Implementation details</li>
<li>Statements</li>
</ul>
<ul style="list-style: none; margin: 2rem 0 0; text-align: right; width: 50%">
<li>Concerned with <em>what</em></li>
<li>Abstraction</li>
<li>Expressions</li>
</ul>
</div>
</div>
<div class="fragment fade-in-then-out">
<div style="display: flex; justify-content: space-between">
<ul style="list-style: none; margin: 2rem 0 0">
<li>Concerned with <em>how</em></li>
<li>Implementation details</li>
<li>Statements</li>
<li>Requires <em>reading</em></li>
</ul>
<ul style="list-style: none; margin: 2rem 0 0; text-align: right; width: 50%">
<li>Concerned with <em>what</em></li>
<li>Abstraction</li>
<li>Expressions</li>
<li>Requires <em>knowledge</em></li>
</ul>
</div>
</div>
</div>
<pre class="fragment fade-in-then-out" data-arrow-left="5%"><code class="ts" data-trim data-noescape>
const charCodes = [115, null, 104, 105, 116]
let result = ''
for (let i = 0; i < charCodes.length; i++) {
const charCode = charCodes[i]
if (!charCode) {
continue
}
result += String.fromCharCode(charCode)
}
result // <mark>'shit'</mark>
</code></pre>
<pre class="fragment fade-in-then-out" data-arrow-left="40%"><code class="ts" data-trim data-noescape>
const charCodes = [98, 101, 116, 116, 101, null, 114]
const result = charCodes
.filter((charCode) => charCode)
.map((charCode) => String.fromCharCode(charCode))
.join('')
result // <mark>'better'</mark>
</code></pre>
<pre class="fragment fade-in-then-out" data-arrow-left="70%"><code class="ts" data-trim data-noescape>
const charCodes = [110, 105, null, 99, 101]
const makeWord = pipe(
reject(isNil),
map(String.fromCharCode),
join('')
)
makeWord(charCodes) // <mark>'nice'</mark>
</code></pre>
<pre class="fragment fade-in-then-out" data-arrow-left="95%"><code class="ts" data-trim data-noescape>
const incCount = ifElse(
has('count'),
over(lensProp('count'), inc),
assoc('count', 1)
)
incCount({}) // { count: 1 }
incCount({ count: 1 }) // { count: 2 }
</code></pre>
</section>
<!-- <section>
<aside class="notes">
<p>Comparable: estimating a BE story when you're a FE dev</p>
</aside>
<h3 class="r-fit-text">
Familiarity can be acquired;<br />complexity is intrinsic.
<cite><a href="https://sanctuary.js.org/#section:currying" target="_blank">sanctuary.js</a></cite>
</h3>
</section> -->
</section>
<section>
<section>
<h3>Equine alchemy</h3>
<div class="fragment">
Starting code:
<pre><code class="ts" data-trim data-line-numbers="1,5|1-2,5|1-3,5|1-5|all">
const toUnicorn = (horse) => {
const whiteHorse = paint(🥛, horse)
const hornedWhiteHorse = attach(🐚, whiteHorse)
return feed(🌈, ✨, hornedWhiteHorse)
}
toUnicorn(🐴) // 🦄
</code></pre>
</div>
<div class="fragment">
End result:
<pre><code class="ts" data-trim data-noescape data-line-numbers>
const toUnicorn = pipe(paint(🥛), attach(🐚), feed(🌈, ✨))
toUnicorn(🐴) // 🦄
</code></pre>
</div>
</section>
<section>
<h3>Pipeline</h3>
<p class="fragment"><code>pipe = (…fns) → (a) → b</code></p>
<pre class="fragment"><code class="ts" data-trim data-line-numbers="1|1-3,7|1-4,7|1-5,7|1-7|all">
import { pipe } from 'ramda' // or: 'lodash/fp'
const toUnicorn = (horse) => pipe(
(horse) => paint(🥛, horse),
(whiteHorse) => attach(🐚, whiteHorse),
(hornedWhiteHorse) => feed(🌈, ✨, hornedWhiteHorse)
)(horse)
toUnicorn(🐴) // 🦄
</code></pre>
</section>
<section>
<h3>Currying</h3>
<!-- <p class="fragment fade-in-then-out" style="text-align: left">
…the technique of converting a function that takes multiple arguments into a sequence of functions that
each take a single argument.
<cite><a href="https://en.wikipedia.org/wiki/Currying" target="_blank">Wikipedia</a></cite>
</p> -->
<pre class="fragment" style="width: 100%"><code class="ts" data-trim data-line-numbers="1|1-2|1-4|all">
const curriedPaint = (color) => (thing) => paint(color, thing)
const curriedAttach = (item) => (thing) => attach(item, thing)
const curriedFeed = (food1) => (food2) => (thing)
=> feed(food1, food2, thing)
const toUnicorn = (horse) => pipe(
curriedPaint(🥛),
curriedAttach(🐚),
curriedFeed(🌈)(✨)
)(horse)
toUnicorn(🐴) // 🦄
</code></pre>
</section>
<section class="r-stretch">
<h3 class="r-fit-text">Tacit (point-free) programming</h3>
<!-- <p class="fragment fade-in-then-out" style="text-align: left">
A style of programming where function arguments (<em>points</em>) are never explicitly referenced.
</p> -->
<pre
class="fragment fade-in-then-out"
style="width: 100%"
><code class="ts" data-trim data-noescape data-line-numbers>
<br>
<br>
const curriedPaint = (color) => (thing) => paint(color, thing)
const curriedAttach = (item) => (thing) => attach(item, thing)
const curriedFeed = (food1) => (food2) => (thing)
=> feed(food1, food2, thing)
const toUnicorn = (horse) => pipe(
curriedPaint(🥛),
curriedAttach(🐚),
curriedFeed(🌈)(✨)
)(horse)
toUnicorn(🐴) // 🦄
</code></pre>
<pre
class="fragment fade-in-then-out"
style="width: 100%"
><code class="ts" data-trim data-noescape data-line-numbers>
<br>
<br>
const curriedPaint = (color) => (thing) => paint(color, thing)
const curriedAttach = (item) => (thing) => attach(item, thing)
const curriedFeed = (food1) => (food2) => (thing)
=> feed(food1, food2, thing)
const toUnicorn = pipe(
curriedPaint(🥛),
curriedAttach(🐚),
curriedFeed(🌈)(✨)
)
toUnicorn(🐴) // 🦄
</code></pre>
<pre
class="fragment fade-in-then-out"
style="width: 100%"
><code class="ts" data-trim data-noescape data-line-numbers>
import { curry } from 'ramda' // or: 'lodash/fp'
const curriedPaint = curry(paint)
const curriedAttach = curry(attach)
const curriedFeed = curry(feed)
const toUnicorn = pipe(
curriedPaint(🥛),
curriedAttach(🐚),
curriedFeed(🌈, ✨)
)
toUnicorn(🐴) // 🦄
</code></pre>
<pre
class="fragment fade-in-then-out"
style="width: 100%"
><code class="ts" data-trim data-noescape data-line-numbers>
import { curry } from 'ramda' // or: 'lodash/fp'
const paint = curry((color, thing) => /* paint thing */)
const attach = curry((item, thing) => /* attach thing */)
const feed = curry((food1, food2, thing) => /* feed thing */)
const toUnicorn = pipe(
paint(🥛),
attach(🐚),
feed(🌈, ✨)
)
toUnicorn(🐴) // 🦄
</code></pre>
<div class="fragment">
Starting code:
<pre style="width: 100%"><code class="ts" data-trim data-line-numbers>
const toUnicorn = (horse) => {
const whiteHorse = paint(🥛, horse)
const hornedWhiteHorse = attach(🐚, whiteHorse)
return feed(🌈, ✨, hornedWhiteHorse)
}
toUnicorn(🐴) // 🦄
</code></pre>
End result:
<pre style="width: 100%"><code class="ts" data-trim data-noescape data-line-numbers>
const toUnicorn = pipe(paint(🥛), attach(🐚), feed(🌈, ✨))
toUnicorn(🐴) // 🦄
</code></pre>
</div>
</section>
</section>
<section>
<h2 class="gradient-text">Questions?</h2>
<!--
Point-free programming might be difficult (e.g. Number.parseInt())
Using `this` makes it harder to be point-free
https://medium.com/dailyjs/functional-js-7-point-free-style-b21a1416ac6a
https://wiki.haskell.org/Pointfree#Problems_with_pointfree
Further reading:
* https://medium.com/dailyjs/functional-js-1-introduction-7908bfe5ef8d
* https://project-awesome.org/stoeffel/awesome-fp-js
* https://en.wikipedia.org/wiki/Tacit_programming
Libs:
* Ramda.js
* Rambda https://selfrefactor.github.io/rambda/#/
* Lodash FP?
* https://sanctuary.js.org/
* https://folktale.origamitower.com/ (more OO)
* https://www.purescript.org/
Future subjects:
* combinators
-->
</section>
</div>
</div>
<script src="dist/reveal.js"></script>
<script src="plugin/notes/notes.js"></script>
<script src="plugin/markdown/markdown.js"></script>
<script src="plugin/highlight/highlight.js"></script>
<script>
// More info about initialization & config:
// - https://revealjs.com/initialization/
// - https://revealjs.com/config/
Reveal.initialize({
hash: true,
slideNumber: true,
// Learn about plugins: https://revealjs.com/plugins/
plugins: [RevealMarkdown, RevealHighlight, RevealNotes],
})
const log = (val) => {
console.log(val)
return val
}
const find = (fn) => (array) => array.find(fn)
const pipe = (...fns) => (val) => fns.reduce((acc, fn) => fn(acc), val)
const getDataFor = (key) => (el) => el.dataset[key]
const isVisible = (el) => el.classList.contains('current-fragment')
const setStyle = (el) => (prop) => (value) => (el.style[prop] = value)
const arrow = document.querySelector('.gradient-arrow')
const codeSnippets = [...document.querySelectorAll('[data-arrow-left]')]
const setArrowStyle = setStyle(arrow)
const setArrowOpacity = setArrowStyle('opacity')
const setArrowPosition = pipe(getDataFor('arrowLeft'), setArrowStyle('left'))
const updateArrowStyle = () => {
const activeCodeSnippet = find(isVisible)(codeSnippets)
if (activeCodeSnippet) {
setArrowOpacity(1)
setArrowPosition(activeCodeSnippet)
return
}
setArrowOpacity(0)
}
Reveal.on('fragmentshown', updateArrowStyle)
Reveal.on('fragmenthidden', updateArrowStyle)
</script>
</body>
</html>