-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
240 lines (190 loc) · 7.61 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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>functional.js - MancJS lightning talk slides</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, minimal-ui">
<link rel="stylesheet" href="css/reveal.css">
<link rel="stylesheet" href="css/fjs.css">
<link rel="stylesheet" href="css/highlight.css">
<link href="http://fonts.googleapis.com/css?family=Raleway:300" rel="stylesheet" type="text/css">
<!--[if lt IE 9]><script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
</head>
<body>
<div class="reveal">
<div class="slides">
<section>
<img alt="functional.js" src="http://functionaljs.com/css/images/[email protected]" />
<h1>functional.js</h1>
<p>
<a href="http://functionaljs.com" target="_blank">docs</a> /
<a href="https://github.com/leecrossley/functional-js" target="_blank">source</a>
</p>
<p><small>
<a href="https://twitter.com/lee_crossley" target="_blank">@lee_crossley</a> /
<a href="http://ilee.co.uk" target="_blank">ilee.co.uk</a>
</small></p>
</section>
<section>
<h3>Straight in...</h3>
<pre><code spellcheck="false" data-trim contenteditable>
var enabledProducts = [];
for (var i = 0; i < products.length; i++) {
if (products[i].enabled) {
enabledProducts.push(products[i]);
}
}
</code></pre>
<h4>With fjs</h4>
<pre><code spellcheck="false" data-trim contenteditable>
var enabledProducts = fjs.select(function(item) {
return item.enabled;
}, products);
</code></pre>
<p><small>
<a href="http://functionaljs.com/collections/select-filter/" target="_blank">view in docs</a>
</small></p>
</section>
<section>
<h3>Skinning the cat</h3>
<pre><code spellcheck="false" data-trim contenteditable>
var enabledProducts = fjs.select(function(item) {
return item.enabled;
}, products);
</code></pre>
<h4>Currying for reuse</h4>
<pre><code spellcheck="false" data-trim contenteditable>
var enabled = function (item) {
return item.enabled;
};
var selectEnabled = fjs.select(enabled);
selectEnabled(products);
</code></pre>
<p><small>
<a href="http://functionaljs.com/collections/select-filter/" target="_blank">view in docs</a>
</small></p>
</section>
<section>
<h3>More techniques</h3>
<h4>Lambda expressions</h4>
<pre><code spellcheck="false" data-trim contenteditable>
var enabledProducts = fjs.select("p => p.enabled", products);
</code></pre>
<h4>Curried lambda expression</h4>
<pre><code spellcheck="false" data-trim contenteditable>
var selectEnabled = fjs.select("p => p.enabled");
selectEnabled(products);
</code></pre>
<p><small>
<a href="http://functionaljs.com/basics/lambda/" target="_blank">view in docs</a>
</small></p>
</section>
<section>
<h3>fjs functions for collections</h3>
<p>each, map, reduce, fold, apply, every, any, select, pluck, toArray, first, last, best, partition, group, while</p>
<p><small>
<a href="http://functionaljs.com/collections/each/" target="_blank">view in docs</a>
</small></p>
</section>
<section>
<h3>Fold product prices</h3>
<pre><code spellcheck="false" data-trim contenteditable>
var add = function (a, b) {
return a + b;
};
var sum = fjs.fold(add, 0);
sum(prices);
</code></pre>
<pre><code spellcheck="false" data-trim contenteditable>
fjs.fold("a, b => a + b", 0, prices);
</code></pre>
<p><small>
<a href="http://functionaljs.com/collections/fold/" target="_blank">view in docs</a>
</small></p>
</section>
<section>
<h3>From the DOM</h3>
<pre><code spellcheck="false" data-trim contenteditable>
var $ = document.querySelectorAll.bind(document);
var prices = [].slice.call($(".price"));
fjs.fold("a, b => a + b", 0, prices);
</code></pre>
<p><small>
<a href="http://functionaljs.com/collections/fold/" target="_blank">view in docs</a>
</small></p>
</section>
<section>
<h3>Roll your own</h3>
<pre><code spellcheck="false" data-trim contenteditable>
var converter = fjs.curry(function(rate, symbol, input) {
var output = input * rate;
return symbol + output.toFixed(2);
});
var poundsToUSD = converter(1.52, "$");
var poundsToEUR = converter(1.27, "€");
poundsToUSD(100);
poundsToEUR(50);
</code></pre>
<p><small>
<a href="http://functionaljs.com/basics/curry/" target="_blank">view in docs</a>
</small></p>
</section>
<section>
<h3>Why fjs?</h3>
<ul>
<li>Functional from the ground up but still JS</li>
<li>Consistent implementation</li>
<li>Client (cross browser, mobile) / Server (nodejs)</li>
<li>< 2kB minified and gzipped</li>
<li>Best curry you'll get anywhere</li>
</ul>
</section>
<section>
<h3>There's much, much more</h3>
<ul>
<li>Multiple function composition with fjs.compose</li>
<li>Extending function arity beyond the expected length</li>
</ul>
</section>
<section>
<h3>Try it</h3>
<ul>
<li>npm install functional.js --save</li>
<li>bower install functional.js</li>
<li>http://bit.ly/funcmin</li>
<li>here (open your dev console)</li>
</ul>
</section>
<section>
<h3>Get involved</h3>
<ul>
<li><a href="https://github.com/leecrossley/functional-js" target="_blank">Open source</a></li>
<li><a href="https://github.com/leecrossley/functionaljs-docs" target="_blank">Open docs</a></li>
</ul>
</section>
</div>
</div>
<a class="link" href="https://github.com/leecrossley/functional-js" target="_blank"></a>
<script src="js/head.js"></script>
<script src="js/reveal.js"></script>
<script src="https://cdn.rawgit.com/leecrossley/functional-js/master/functional.min.js"></script>
<script>
Reveal.initialize({
controls: true,
progress: true,
history: true,
center: true,
transition: "none",
dependencies: [
{
src: "js/highlight.js",
async: true,
callback: function() {
hljs.initHighlightingOnLoad();
}
}
]
});
</script>
</body>
</html>