-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
526 lines (526 loc) · 38.2 KB
/
index.html
File metadata and controls
526 lines (526 loc) · 38.2 KB
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
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head><title>dysfunctional.JS</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<link rel="stylesheet" type="text/css" href="common.css">
</head>
<body>
<h1>dysfunctional.JS</h1>
<p>This is <a href="http://www.godsboss.de/" hreflang="de" title="Beware! German content!">my</a> <a href="#license">free</a> JavaScript, or ECMAScript, library. Although it may be dysfunctional, it's still functional.</p>
<p>Because I like reinventing the wheel, a small self-made framework is used for testing the library. Just <a href="test.html">test the library</a>!</p>
<p>You can <a href="http://github.com/GodsBoss/dysfunctionaljs">get it via GitHub</a> or just <a href="dysfunctional.js">download it</a>!</p>
<div id="spirit" class="section">
<h2>Spirit</h2>
<p>The library is mostly functional, but provides optional prototypal extensions of <code>Array</code>, <code>Boolean</code>, <abbr title="et cetera">etc.</abbr> (but not <code>Object</code>). The namespace is flat, there is no <code>library.module.submodule.evenmorsubmodule.RandomClass.property</code> madness. All exposed functions can be found directly as properties of the library. If you think "dysfunctional" is a long name, just rename it, it should be easy.</p>
<p>I try to make dysfunctional.JS as pure as possible, <abbr title="id est">i.e.</abbr> the functions should have very few side effects and create new objects, functions or whatever instead.</p>
<h3>Pureness</h3>
<p>A function is called “pure” if it does not have any side effects, meaning its arguments and its environment remains unchanged after execution, and “impure” if not. However, there are functions, namely <code>forEach</code>, which happen to just call other functions but do not return a result value. Although they are pure themselves, without an impure function to be called they are meaningless, so a call usually means there <em>are</em> side effects. Additionally, many other pure functions also call other functions, which may or may be not pure. Summarized, these are the kinds of functions the library contains:</p>
<dl>
<dt>Pure</dt>
<dd>Never has side effects.</dd>
<dt>Likely pure</dt>
<dd>Pure, but can have side effects. You are strongly encouraged to avoid side effects!</dd>
<dt>Unlikely pure</dt>
<dd>Pure itself, but calls most likely have side effects.</dd>
<dt>Impure</dt>
<dd>Function’s purpose includes side effects.</dd>
</dl>
<p>The <a href="#documentation">documentation</a> contains <a href="#functions-by-pureness">every function’s pureness</a>.</p>
<h3>Functionification of language constructs</h3>
<p>JavaScript has first-class functions, but operators (like <code>+</code> or <code>*</code>) are not amongst them, as aren't <code>if</code>-<code>else</code>-constructs or loops (although ECMA-262 5th edition added some useful looping methods for Arrays). Thus I implemented these.</p>
<h3>Higher-order functions</h3>
<p>The real strength of functional languages is the combination of existing functions into new ones. Therefore some higher-order functions, most of them known from other languages like Haskell, are provided.</p>
<h3>Prototypal extensions</h3>
<p>Prototypal extensions are possible, but inactive by default. You can activate them, if you want. See <a href="#function-activatePrototypeExtensions"><code>activatePrototypeExtensions</code></a>.</p>
<h3>Chaining</h3>
<p>At the moment, chaining is neither implemented nor even planned.</p>
</div>
<div id="license" class="section">
<h2>License</h2>
<p>dysfunctional.JS ist distributed under the terms of the <a href="gpl.txt"><abbr title="GNU’s Not Unix">GNU</abbr> <abbr title="General Public License">GPL</abbr> v3</a>.</p>
</div>
<div id="documentation" class="section">
<h2>Documentation</h2>
<div id="function-signatures" class="subsection">
<h3>Function signatures</h3>
<p>A function can have required parameters, which must always be present and either optional parameters or take any number of arguments. A function cannot have both optional and any arguments.</p>
<ul>
<li>Required parameters are just written normally, e.g. <code>function foobar(<var>param1</var>, <var>param2</var>, <var>param3</var>)</code>.</li>
<li>Optional parameters are enclosed in brackets, e.g. <code>function foobar(<var>param1</var> [, <var>param2</var> [, <var>param3</var>]])</code>. Optional parameters are not equal, those with higher indices can only be present if those with lower indices are also used.</li>
<li>If a function takes an arbitrary number of parameters, this is marked with an asterisk, e.g. <code>function foobar(<var>param1</var>, <var>params*</var>)</code>.</li>
</ul>
</div>
<div id="index" class="subsection">
<h3>Index</h3>
<dl class="index">
<dt><a href="#array-functions">Array functions</a></dt>
<dd>
<ul>
<li><a href="#function-every"><code>every</code></a></li>
<li><a href="#function-filter"><code>filter</code></a></li>
<li><a href="#function-first"><code>first</code></a></li>
<li><a href="#function-forEach"><code>forEach</code></a></li>
<li><a href="#function-head"><code>head</code></a></li>
<li><a href="#function-indexOf"><code>indexOf</code></a></li>
<li><a href="#function-last"><code>last</code></a></li>
<li><a href="#function-lastIndexOf"><code>lastIndexOf</code></a></li>
<li><a href="#function-map"><code>map</code></a></li>
<li><a href="#function-range"><code>range</code></a></li>
<li><a href="#function-reduce"><code>reduce</code></a></li>
<li><a href="#function-reduceRight"><code>reduceRight</code></a></li>
<li><a href="#function-some"><code>some</code></a></li>
<li><a href="#function-tail"><code>tail</code></a></li>
</ul>
</dd>
<dt><a href="#boolean-functions">Boolean functions</a></dt>
<dd>
<ul>
<li><a href="#function-and"><code>and</code></a></li>
<li><a href="#function-ifElse"><code>ifElse</code></a></li>
<li><a href="#function-nand"><code>nand</code></a></li>
<li><a href="#function-nor"><code>nor</code></a></li>
<li><a href="#function-not"><code>not</code></a></li>
<li><a href="#function-opIfElse"><code>opIfElse</code></a></li>
<li><a href="#function-or"><code>or</code></a></li>
<li><a href="#function-xnor"><code>xnor</code></a></li>
<li><a href="#function-xor"><code>xor</code></a></li>
</ul>
</dd>
<dt><a href="#collection-functions">Collection functions</a></dt>
<dd>
<ul>
<li><a href="#function-item"><code>item</code></a></li>
<li><a href="#function-items"><code>items</code></a></li>
</ul>
</dd>
<dt><a href="#function-functions">Function functions</a></dt>
<dd>
<ul>
<li><a href="#function-bind"><code>bind</code></a></li>
<li><a href="#function-compose"><code>compose</code></a></li>
<li><a href="#function-constant"><code>constant</code></a></li>
<li><a href="#function-curry"><code>curry</code></a></li>
<li><a href="#function-generator"><code>generator</code></a></li>
<li><a href="#function-hold"><code>hold</code></a></li>
<li><a href="#function-methodToFunction"><code>methodToFunction</code></a></li>
</ul>
</dd>
<dt><a href="#math-functions">Math functions</a></dt>
<dd>
<ul>
<li><a href="#function-arithmeticMean"><code>arithmeticMean</code></a></li>
<li><a href="#function-geometricMean"><code>geometricMean</code></a></li>
<li><a href="#function-harmonicMean"><code>harmonicMean</code></a></li>
<li><a href="#function-median"><code>median</code></a></li>
<li><a href="#function-random"><code>random</code></a></li>
</ul>
</dd>
<dt><a href="#number-functions">Number functions</a></dt>
<dd>
<ul>
<li><a href="#function-add"><code>add</code></a></li>
<li><a href="#function-divide"><code>divide</code></a></li>
<li><a href="#function-even"><code>even</code></a></li>
<li><a href="#function-gt"><code>gt</code></a></li>
<li><a href="#function-gte"><code>gte</code></a></li>
<li><a href="#function-ifSgn"><code>ifSgn</code></a></li>
<li><a href="#function-lt"><code>lt</code></a></li>
<li><a href="#function-lte"><code>lte</code></a></li>
<li><a href="#function-modulo"><code>modulo</code></a></li>
<li><a href="#function-multiply"><code>multiply</code></a></li>
<li><a href="#function-negate"><code>negate</code></a></li>
<li><a href="#function-odd"><code>odd</code></a></li>
<li><a href="#function-opIfSgn"><code>opIfSgn</code></a></li>
<li><a href="#function-product"><code>product</code></a></li>
<li><a href="#function-reciprocal"><code>reciprocal</code></a></li>
<li><a href="#function-sgn"><code>sgn</code></a></li>
<li><a href="#function-subtract"><code>subtract</code></a></li>
<li><a href="#function-sum"><code>sum</code></a></li>
</ul>
</dd>
<dt><a href="#object-functions">Object functions</a></dt>
<dd>
<ul>
<li><a href="#function-everyProperty"><code>everyProperty</code></a></li>
<li><a href="#function-filterProperties"><code>filterProperties</code></a></li>
<li><a href="#function-forEachProperty"><code>forEachProperty</code></a></li>
<li><a href="#function-inject"><code>inject</code></a></li>
<li><a href="#function-keys"><code>keys</code></a></li>
<li><a href="#function-mapProperties"><code>mapProperties</code></a></li>
<li><a href="#function-merge"><code>merge</code></a></li>
<li><a href="#function-someProperty"><code>someProperty</code></a></li>
<li><a href="#function-values"><code>values</code></a></li>
</ul>
</dd>
<dt><a href="#string-functions">String functions</a></dt>
<dd>
<ul>
<li><a href="#function-ltrim"><code>ltrim</code></a></li>
<li><a href="#function-rtrim"><code>rtrim</code></a></li>
<li><a href="#function-trim"><code>trim</code></a></li>
</ul>
</dd>
<dt><a href="#misc-functions">Miscellaneous functions</a></dt>
<dd>
<ul>
<li><a href="#function-fThrow"><code>fThrow</code></a></li>
<li><a href="#function-id"><code>id</code></a></li>
<li><a href="#function-loop"><code>loop</code></a></li>
<li><a href="#function-noOp"><code>noOp</code></a></li>
<li><a href="#function-tryCatch"><code>tryCatch</code></a></li>
<li><a href="#function-until"><code>until</code></a></li>
</ul>
</dd>
<dt><a href="#library-functions">Library functions</a></dt>
<dd>
<ul>
<li><a href="#function-activatePrototypeExtensions"><code>activatePrototypeExtensions</code></a></li>
<li><a href="#function-addMethod"><code>addMethod</code></a></li>
</ul>
</dd>
</dl>
</div>
<div id="array-functions" class="subsection">
<h3>Array functions</h3>
<p>All functions which manipulate arrays or operate on them.</p>
<dl>
<dt id="function-every"><code>every(<var>arr</var>, <var>func</var>, [, <var>context</var>])</code></dt>
<dd>Checks if for every element of <var>arr</var> a condition is <code>true</code>. Roughly equivalent to <code><var>arr</var>.every(<var>func</var>, <var>context</var>)</code>. Always <code>true</code> for empty arrays.</dd>
<dt id="function-filter"><code>filter(<var>arr</var>, <var>func</var> [, <var>context</var>])</code></dt>
<dd>Collects only elements of <var>arr</var>, for which the return value of a call to <var>func</var> with <var>context</var> as <code>this</code> value coerces to <code>true</code>. Roughly equivalent to <code><var>arr</var>.filter(<var>func</var>, <var>context</var>)</code>.</dd>
<dt id="function-first"><code>first(<var>arr</var>)</code></dt>
<dd>Returns the first element of <var>arr</var>. Throws a <code>TypeError</code> if the array is empty.</dd>
<dt id="function-forEach"><code>forEach(<var>arr</var>, <var>func</var> [, <var>context</var>])</code></dt>
<dd>Calls <var>func</var> for all elements of <var>arr</var> with <var>context</var> as <code>this</code>. Roughly equivalent to <code><var>arr</var>.forEach(<var>func</var>, <var>context</var>)</code>.</dd>
<dt id="function-head"><code>head(<var>arr</var> [, <var>n</var>])</code></dt>
<dd>Returns the first <var>n</var> elements of <var>arr</var>. The default value for <var>n</var> is 1.</dd>
<dt id="function-indexOf"><code>indexOf(<var>arr</var>, <var>value</var> [, <var>startIndex</var>])</code></dt>
<dd>Returns the index of the first appearance of <var>value</var> within <var>arr</var>, or <code>-1</code>, if that value does not exist within <var>arr</var>. The search will start at <var>startIndex</var> or at <code>0</code>, if <var>startIndex</var> is not given.</dd>
<dt id="function-last"><code>last(<var>arr</var>)</code></dt>
<dd>Returns the last element of <var>arr</var>. Throws a TypeError, if the array is empty.</dd>
<dt id="function-lastIndexOf"><code>lastIndexOf(<var>arr</var>, <var>value</var> [, <var>startIndex</var>])</code></dt>
<dd>Returns the index of the last appearance of <var>value</var> within <var>arr</var>, or <code>-1</code>, if that value does not exist within <var>arr</var>. The search will start at <var>startIndex</var> or, if it is missing, at <code><var>arr</var>.length</code>.</dd>
<dt id="function-map"><code>map(<var>arr</var>, <var>func</var> [, <var>context</var>)</code></dt>
<dd>Creates a new array by applying <var>func</var> to all elements of <var>arr</var> with <var>context</var> as <code>this</code> value and collecting the results. Roughly equivalent to <code><var>arr</var>.map(<var>func</var>, <var>context</var>)</code>.</dd>
<dt id="function-range"><code>range([<var>start</var>, ] <var>stop</var> [, <var>step</var>])</code></dt>
<dd>Works similar to <a href="http://www.python.org/">Python</a>'s <a href="http://docs.python.org/release/2.6.5/library/functions.html#range"><code>range</code></a> function. Creates an array from <var>start</var> to <var>stop</var> with distance <var>step</var>. If <var>step</var> is omitted, a default value of <code>1</code> is used, if additionally <var>start</var> is omitted, a default value of <code>0</code> is assumed. <var>step</var> may be negative.</dd>
<dt id="function-reduce"><code>reduce(<var>arr</var>, <var>func</var> [, <var>startValue</var>])</code></dt>
<dd>Reduces the values of <var>arr</var> via successive calls to <var>func</var> to a result and returns it. The array is processed from start (index 0) to end (index <code><var>arr</var>.length-1</code>). Roughly equivalent to <code><var>arr</var>.reduce(<var>func</var>, <var>startValue</var>)</code>.</dd>
<dt id="function-reduceRight"><code>reduceRight(<var>arr</var> [, <var>startValue</var>])</code></dt>
<dd>Reduces the values of <var>arr</var> via successive calls to <var>func</var> to a result and returns it. The array is processed from end (index <code><var>arr</var>.length-1</code>) to start (index 0). Roughly equivalent to <code><var>arr</var>.reduceRight(<var>func</var>, <var>startValue</var>)</code>.</dd>
<dt id="function-some"><code>some(<var>arr</var>, <var>func</var> [, <var>context</var>)</code></dt>
<dd>Checks if at least one element of <var>array</var> satisfies a given condition. Roughly equivalent to <code><var>arr</var>.some(<var>func</var>, <var>context</var>)</code>. Always <code>false</code> for empty arrays.</dd>
<dt id="function-tail"><code>tail(<var>arr</var> [, <var>n</var>])</code></dt>
<dd>Returns the last <var>n</var> elements of <var>arr</var>. The default value for <var>n</var> is 1.</dd>
</dl>
</div>
<div id="boolean-functions" class="subsection">
<h3>Boolean functions</h3>
<dl>
<dt id="function-and"><code>and(<var>left</var>, <var>right</var>)</code></dt>
<dd>Returns <code>true</code>, if both <var>left</var> and <var>right</var> are truthy, else <code>false</code>.</dd>
<dt id="function-ifElse"><code>ifElse(<var>b</var>, <var>fIf</var>, <var>fElse</var> [, <var>context</var>])</code></dt>
<dd>If <var>b</var> is truthy, <var>fIf</var> is called, else <var>fElse</var>. If <var>context</var> is given, it's the <code>this</code> value of the function. The return value is the return value of the called function.</dd>
<dt id="function-nand"><code>nand(<var>left</var>, <var>right</var>)</code></dt>
<dd>Returns <code>true</code>, if at least one of the arguments is falsy, else <code>false</code>.</dd>
<dt id="function-nor"><code>nor(<var>left</var>, <var>right</var>)</code></dt>
<dd>Returns <code>true</code>, if both <var>left</var> and <var>right</var> are falsy, else <code>false</code>.</dd>
<dt id="function-not"><code>not(<var>b</var>)</code></dt>
<dd>Returns <code>!<var>b</var></code>.</dd>
<dt id="function-opIfElse"><code>opIfElse(<var>b</var>, <var>ifValue</var>, <var>elseValue</var>)</code></dt>
<dd>Returns <var>ifValue</var>, if <var>b</var> is truthy, else <var>elseValue</var>.</dd>
<dt id="function-or"><code>or(<var>left</var>, <var>right</var>)</code></dt>
<dd>Returns <code>true</code>, if at least one of the arguments is truthy, else <code>false</code>.</dd>
<dt id="function-xnor"><code>xnor(<var>left</var>, <var>right</var>)</code></dt>
<dd>Returns <code>true</code>, if both <var>left</var> and <var>right</var> are either truthy or falsy. If one of them is truthy and the other one is falsy, returns <code>false</code>.</dd>
<dt id="function-xor"><code>xor(<var>left</var>, <var>right</var>)</code></dt>
<dd>Returns <code>true</code>, if either <var>left</var> or <var>right</var> is truthy. If both are truthy or if both are falsy, returns <code>false</code>.</dd>
</dl>
</div>
<div id="collection-functions" class="subsection">
<h3>Collection functions</h3>
<p>Some functions apply to both arrays and objects and maybe to other things.</p>
<dl>
<dt id="function-item"><code>item(<var>obj</var>, <var>index</var>)</code></dt>
<dd>Returns <code><var>obj</var>[<var>index</var>]</code>. <var>obj</var> can be an object or an array, while <var>index</var> is a property or an index.</dd>
<dt id="function-items"><code>items(<var>obj</var> [, <var>indices*</var>])</code></dt>
<dd>Returns properties of an object or elements of an array as array.</dd>
</dl>
</div>
<div id="function-functions" class="subsection">
<h3>Function functions</h3>
<p>Create functions out of anything!</p>
<dl>
<dt id="function-bind"><code>bind(<var>f</var>, <var>o</var>)</code></dt>
<dd>Takes a function <var>f</var> and an object <var>o</var> and returns a new function, which takes all arguments, calls <var>f</var> with them as arguments and <var>o</var> as the <var>this</var> value and returns the result.</dd>
<dt id="function-compose"><code>compose(<var>f</var> [, <var>functions*</var>]</code></dt>
<dd>Composes a new function by wrapping <var>f</var> in all additional arguments (which must be functions as well). The new function takes the same arguments as <var>f</var>, and returns a value resulting from a call to <var>f</var> with these arguments and then chaining calls to all other functions, in order.</dd>
<dt id="function-constant"><code>constant(<var>c</var>)</code></dt>
<dd>Creates a function which always returns <var>c</var>.</dd>
<dt id="function-curry"><code>curry(<var>f</var> [, <var>n</var>]</code></dt>
<dd>Curries a function.</dd>
<dt id="function-generator"><code>generator(<var>f</var>, <var>startValue</var> [, <var>extract</var>])</code></dt>
<dd>Creates a generator. A generator is a function which is call sequently without arguments and returns a different value (sometimes called ”next“). If <var>extract</var> is not given, <var>id</var> is used instead. The values of the created generator are computed by applying <var>f</var> to the current value (which is <var>startValue</var> in the beginning) and extracting the real return value via <var>extract</var>. <var>f</var> is a function which can take any number of arguments, but <em>must</em> return an array. The <var>startValue</var> must be an array, too, and is not returned on the first execution.</dd>
<dt id="function-hold"><code>hold(<var>f</var> [, <var>args*</var>])</code></dt>
<dd>Takes a function <var>f</var> and additional arguments <var>args</var>. Returns a function which calls <var>f</var> with the same <code>this</code> value and the stored arguments (<var>args</var>). The returned function ignores all of their own arguments.</dd>
<dt id="function-methodToFunction"><code>methodToFunction(<var>name</var>)</code></dt>
<dd>Creates a new function. This new function takes an object parameter <var>obj</var> and additional arguments. It calls <var>obj</var>'s method name <var>name</var> with <var>obj</var> as <code>this</code>, the additional arguments as arguments and returns the result of that method call.</dd>
</dl>
</div>
<div id="math-functions" class="subsection">
<h3>Math functions</h3>
<p>For small functions operating on numbers, see <a href="#number-functions">number functions</a>.</p>
<dl>
<dt id="function-arithmeticMean"><code>arithmeticMean(<var>values</var> [, <var>comparator</var>])</code></dt>
<dd>Returns the arithmetic mean of the <var>values</var>. If no <var>comparator</var> is given, standard numeric comparison is used.</dd>
<dt id="function-geometricMean"><code>geometricMean(<var>values</var> [, <var>mul</var>, <var>pow</var>])</code></dt>
<dd>Returns the geometric mean of the <var>values</var>. Uses <var>mul</var> for multiplication and <var>pow</var> for power, the default values are <a href="#function-multiply"><code>multiply</code></a> and standard power (<code>Math.pow</code>).</dd>
<dt id="function-harmonicMean"><code>harmonicMean(<var>values</var> [, <var>add</var>, <var>div</var>, <var>unit</var>])</code></dt>
<dd>Returns the harmonic mean of the <var>values</var>. Uses <var>add</var> for adding values, <var>div</var> for dividing values and <var>unit</var> as the mathematical unit. The default for these three arguments are (in order) <a href="#function-add"><code>add</code></a>, <a href="#function-divide"><code>divide</code></a> and <code>1</code>.</dd>
<dt id="function-median"><code>median(<var>values</var> [, <var>comparator</var>])</code></dt>
<dd>Returns the median of the <var>values</var>. The <var>comparator</var> must be a function like those accepted by <code>Array.prototype.sort</code> (i.e. for <var>x</var><<var>y</var> these must be true: <code><var>comparator</var>(<var>x</var>, <var>x</var>)==0</code>, <code><var>comparator</var>(<var>x</var>, <var>y</var>)<0</code> and <code><var>comparator</var>(<var>y</var>, <var>x</var>)>0</code>). If no <var>comparator</var> is given, the default numeric comparison is used.</dd>
<dt id="function-random"><code>random(<var>min</var>, <var>max</var>)</code></dt>
<dd>Returns a random integer, which is at least <var>min</var>, but not more than <var>max</var>.</dd>
</dl>
</div>
<div id="number-functions" class="subsection">
<h3>Number functions</h3>
<p>All functions directly involved with numbers. Does not contain complicated <a href="#math-functions">mathematical functions</a>.</p>
<dl>
<dt id="function-add"><code>add(<var>a</var>, <var>b</var>)</code></dt>
<dd>Adds <var>a</var> and <var>b</var> and returns the result.</dd>
<dt id="function-divide"><code>divide(<var>a</var>, <var>b</var>)</code></dt>
<dd>Divides <var>a</var> by <var>b</var> and returns the result.</dd>
<dt id="function-even"><code>even(<var>n</var>)</code></dt>
<dd>Returns <code>true</code>, if <var>n</var> is even, else <code>false</code>.</dd>
<dt id="function-gt"><code>gt(<var>left</var>, <var>right</var>)</code></dt>
<dd><p>Returns <code>true</code>, if <var>left</var> is greater than <var>right</var>, and <code>false</code>, if not.</p></dd>
<dt id="function-gte"><code>gte(<var>left</var>, <var>right</var>)</code></dt>
<dd><p>Returns <code>true</codE>, if <var>left</var> is greater than or equals <var>right</var>, and <code>false</code>, if not.</p></dd>
<dt id="function-ifSgn"><code>ifSgn(<var>x</var>, <var>negF</var>, <var>zeroF</var>, <var>posF</var> [, <var>context</var>])</code></dt>
<dd>Dependant on the signum of <var>x</var>, call a function –
<ul>
<li><var>negF</var>, if the number is negative.</li>
<li><var>zeroF</var>, if the number is zero.</li>
<li><var>posF</var>, if the number is positive.</li>
</ul>
If <var>context</var> is given, it is used as the function’s <code>this</code> value.</dd>
<dt id="function-lt"><code>lt(<var>left</var>, <var>right</var>)</code></dt>
<dd><p>Returns <code>true</code>, if <var>left</var> is lesser than <var>right</var>, and <code>false</code>, if not.</p></dd>
<dt id="function-lte"><code>lte(<var>left</var>, <var>right</var>)</code></dt>
<dd><p>Returns <code>true</code>, if <var>left</var> is lesser than or equals <var>right</var>, and <code>false</code>, if not.</p></dd>
<dt id="function-modulo"><code>modulo(<var>n</var>, <var>mod</var>)</code></dt>
<dd>Functification of the modulo operator (<code>%</code>). Unlike the builtin JavaScript operator, the function never returns a negative number, even if <var>n</var> is lesser than zero.</dd>
<dt id="function-multiply"><code>multiply(<var>a</var>, <var>b</var>)</code></dt>
<dd>Multiplies <var>a</var> and <var>b</var> and returns the result.</dd>
<dt id="function-negate"><code>negate(<var>x</var>)</code></dt>
<dd>Returns <code>-<var>x</var></code>.</dd>
<dt id="function-odd"><code>odd(<var>n</var>)</code></dt>
<dd>Returns <code>true</code>, if <var>n</var> is odd, else <code>false</code>.</dd>
<dt id="function-opIfSgn"><code>opIfSgn(<var>x</var>, <var>negV</var>, <var>zeroV</var>, <var>posV</var>)</code></dt>
<dd>Returns a value according to the signum of a number <var>x</var>.
<ul>
<li><var>negV</var>, if the number is negative.</li>
<li><var>zeroV</var>, if it is zero.</li>
<li><var>posV</var>, if it is positive.</li>
</ul>
<dt id="function-product"><code>product(<var>n*</var>)</code></dt>
<dd>Multiplies all arguments and returns the result. If no arguments were provided, <code>1</code> is returned.</dd>
<dt id="function-reciprocal"><code>reciprocal(<var>x</var>)</code></dt>
<dd>Returns <code>1/<var>x</var></code>.</dd>
<dt id="function-sgn"><code>sgn(<var>x</var>)</code></dt>
<dd>Returns the signum of <var>x</var>, either <code>-1</code> (if negative), <code>0</code> (if zero) or <code>1</code> (if positive).</dd>
<dt id="function-subtract"><code>subtract(<var>a</var>, <var>b</var>)</code></dt>
<dd>Subtracts <var>b</var> from <var>a</var> and returns the result.</dd>
<dt id="function-sum"><code>sum(<var>n*</var>)</code></dt>
<dd>Returns the sum of all arguments. If no arguments were provided, <code>0</code> is returned.</dd>
</dl>
</div>
<div id="object-functions" class="subsection">
<h3>Object functions</h3>
<dl>
<dt id="function-everyProperty"><code>everyProperty(<var>obj</var>, <var>condition</var> [, <var>context</var>])</code></dt>
<dd>Checks if every property of <var>obj</var> satisfies a given <var>condition</var>, which is called with three arguments (in order) and with <var>context</var> as <code>this</code> value:
<ol>
<li>Property value</li>
<li>Property name</li>
<li><var>obj</var></li>
</ol>
This is an object version of <a href="#function-every"><code>every</code></a>.</dd>
<dt id="function-filterProperties"><code>filterProperties(<var>obj</var>, <var>condition</var> [, <var>context</var>])</code></dt>
<dd>Creates a new object with properties from <var>obj</var>, but only those, for which a given <var>condition</var>, called with <var>context</var> as <code>this</code> value, is truthy. This <var>condition</var> is called with three arguments (in order):
<ol>
<li>Property value</li>
<li>Property name</li>
<li><var>obj</var></li>
</ol>
This is an object version of <a href="#function-filter"><code>filter</code></a>.</dd>
<dt id="function-forEachProperty"><code>forEachProperty(<var>obj</var>, <var>f</var> [, <var>context</var>])</code></dt>
<dd>Calls <var>f</var> for every property of <var>obj</var> with <var>context</var> as <code>this</code> value and these arguments (in order):
<ol>
<li>Property value</li>
<li>Property name</li>
<li><var>obj</var></li>
</ol>
This is an object version of <a href="#function-forEach"><code>forEach</code></a>.</dd>
<dt id="function-keys"><code>keys(<var>obj</var> [, <var>all</var>])</code></dt>
<dd>Returns all property names of <var>obj</var> as an array. If <var>all</var> is truthy (default: falsy), includes property names in the prototype chain.</dd>
<dt id="function-inject"><code>inject(<var>target</var>, <var>sources*</var>)</code></dt>
<dd>Injects the propierties of other objects into an objects. Properties are set in order, existing properties will be overwritten. Returns the target object.</dd>
<dt id="function-mapProperties"><code>mapProperties(<var>obj</var>, <var>transform</var> [, <var>context</var>])</code></dt>
<dd>Maps properties from <var>obj</var> into a new object. Therefore, for each property, <var>transform</var> is called with <var>context</var> as <code>this</code> value and with three arguments (in order):
<ol>
<li>Property value</li>
<li>Property name</li>
<li><var>obj</var></li>
</ol>
This is an object version of <a href="#function-map"><code>map</code></a>.</dd>
<dt id="function-merge"><code>merge(<var>objs*</var>)</code></dt>
<dd>Creates a merged version of all objects. The properties of arguments with higher indices <em>overwrite</em> properties from arguments with lower indices. If no argument is provided at all, an “empty” objects is created, like one is created via <code>{}</code> or <code>new Object()</code>.</dd>
<dt id="function-someProperty"><code>someProperty(<var>obj</var>, <var>condition</var> [, <var>context</var>])</code></dt>
<dd>Checks if a given <var>condition</var> is truthy for at least some properties of <var>obj</var>. The <code>this</code> value of the call is <var>context</var> and three arguments are given (in order):
<ol>
<li>Property value</li>
<li>Property name</li>
<li><var>obj</var></li>
</ol>
This is an object version of <a href="#function-some"><code>some</code></a>.</dd>
<dt id="function-values"><code>values(<var>obj</var> [, <var>all</var>])</code></dt>
<dd>Returns all property values of <var>obj</var> as an array. If <var>all</var> is truthy (default: falsy), includes property values in the prototype chain.</dd>
</dl>
</div>
<div id="string-functions" class="subsection">
<h3>String functions</h3>
<p>Functions which manipulate strings.</p>
<dl>
<dt id="function-ltrim"><code>ltrim(<var>s</var>)</code></dt>
<dd>Returns a string which is like <var>s</var>, but with all left whitespace removed.</dd>
<dt id="function-rtrim"><code>rtrim(<var>s</var>)</code></dt>
<dd>Returns a string which is like <var>s</var>, but with all right whitespace removed.</dd>
<dt id="function-trim"><code>trim(<var>s</var>)</code></dt>
<dd>Returns a string which is like <var>s</var>, but with all whitespace on the left and on the right removed.</dd>
</dl>
</div>
<div id="misc-functions" class="subsection">
<h3>Miscellaneous functions</h3>
<dl>
<dt id="function-fThrow"><code>fThrow(<var>exception</var>)</code></dt>
<dd>Functification of <code>throw</code>. Throws <var>exception</var>.</dd>
<dt id="function-id"><code>id(<var>value</var>)</code></dt>
<dd>Identity function. Returns the <var>value</var> given.</dd>
<dt id="function-loop"><code>loop(<var>condition</var>, <var>action</var> [, <var>context</var>])</code></dt>
<dd>Functionified loop. As long as the return value of <var>condition</var> is truthy, <var>action</var> will be called. For both, the <code>this</code> value is <var>context</var>, if given.</dd>
<dt id="function-noOp"><code>noOp()</code></dt>
<dd>Does nothing, returns nothing.</dd>
<dt id="function-tryCatch"><code>tryCatch(<var>tryBlock</var>, <var>catchBlock</var> [, <var>finallyBlock</var> [, <var>elseBlock</var>]])</code></dt>
<dd>Functionified <code>try</code>/<code>catch</code>/<code>else</code>/<code>finally</code>. The <code>else</code> was inspired by the way <a href="http://python.org">Python</a> <a href="http://docs.python.org/py3k/tutorial/errors.html" title="Errors and exceptions in Python 3.1.2">handles exceptions</a>. Tries to execute the <var>tryBlock</var>. If this throws an exception, the <var>catchBlock</var> is executed with one argument, which is the exception thrown by the <var>tryBlock</var>. Without exception, the <var>elseBlock</var>, if given, is called without arguments. The <var>finallyBlock</var>, if given, will be executed either way. If the <var>catchBlock</var> throws an exception, it will be thrown in the end (no return value). If not, the return value is the result of the <var>finallyBlock</var>, if given. Else, if is either the return value of the <var>tryBlock</var> (if no exception occured) or the return value of the <var>catchBlock</var>. The <var>finallyBlock</var> must not throw an exception!</dd>
<dt id="function-until"><code>until(<var>condition</var>, <var>action</var> [, <var>context</var>])</code></dt>
<dd>Functionified loop. As long as the return value of <var>condition</var> is falsy, <var>action</var> will be called. For both, the <code>this</code> value is <var>context</var>, if given.</dd>
</dl>
</div>
<div id="library-functions" class="subsection">
<h3>Library functions</h3>
<p>These functions do not belong to the regular <abbr title="Application Programming Interface">API</abbr>. Instead they fullfill administration/management tasks of the library.</p>
<dl>
<dt id="function-activatePrototypeExtensions"><code>activatePrototypeExtensions()</code></dt>
<dd>Activates dysfunctional.JS’ prototypal extensions.</dd>
<dt id="function-addMethod"><code>addMethod(<var>obj</var>, <var>name</var>, <var>f</var> [, <var>options</var>])</code></dt>
<dd>Adds the function <var>f</var> as a method named <var>name</var> to the object <var>obj</var>. If the property already exists, it will only be overwritten, if <code><var>options</var>.override</code> is truthy. If <code><var>options</var>.thisPosition</code> is a number, <var>obj</var> will be inserted into the arguments at that position for calls to <code><var>object</var>.<var>name</var></code>. The value of that option defaults to 0. If it is <code>null</code>, <var>obj</var> will not be added as argument. In both cases, it will be the <var>this</var> value.</dd>
</dl>
</div>
<div id="functions-by-pureness">
<h3>Functions by pureness</h3>
<h4>Pure</h4>
<ul>
<li><a href="#function-add"><code>add</code></a></li>
<li><a href="#function-and"><code>and</code></a></li>
<li><a href="#function-bind"><code>bind</code></a></li>
<li><a href="#function-compose"><code>compose</code></a></li>
<li><a href="#function-constant"><code>constant</code></a></li>
<li><a href="#function-curry"><code>curry</code></a></li>
<li><a href="#function-divide"><code>divide</code></a></li>
<li><a href="#function-even"><code>even</code></a></li>
<li><a href="#function-first"><code>first</code></a></li>
<li><a href="#function-generator"><code>generator</code></a></li>
<li><a href="#function-gt"><code>gt</code></a></li>
<li><a href="#function-gte"><code>gte</code></a></li>
<li><a href="#function-head"><code>head</code></a></li>
<li><a href="#function-hold"><code>hold</code></a></li>
<li><a href="#function-id"><code>id</code></a></li>
<li><a href="#function-indexOf"><code>indexOf</code></a></li>
<li><a href="#function-item"><code>item</code></a></li>
<li><a href="#function-items"><code>items</code></a></li>
<li><a href="#function-keys"><code>keys</code></a></li>
<li><a href="#function-last"><code>last</code></a></li>
<li><a href="#function-lastIndexOf"><code>lastIndexOf</code></a></li>
<li><a href="#function-lt"><code>lt</code></a></li>
<li><a href="#function-lte"><code>lte</code></a></li>
<li><a href="#function-ltrim"><code>ltrim</code></a></li>
<li><a href="#function-merge"><code>merge</code></a></li>
<li><a href="#function-methodToFunction"><code>methodToFunction</code></a></li>
<li><a href="#function-modulo"><code>modulo</code></a></li>
<li><a href="#function-multiply"><code>multiply</code></a></li>
<li><a href="#function-nand"><code>nand</code></a></li>
<li><a href="#function-negate"><code>negate</code></a></li>
<li><a href="#function-noOp"><code>noOp</code></a></li>
<li><a href="#function-nor"><code>nor</code></a></li>
<li><a href="#function-not"><code>not</code></a></li>
<li><a href="#function-odd"><code>odd</code></a></li>
<li><a href="#function-opIfElse"><code>opIfElse</code></a></li>
<li><a href="#function-opIfSgn"><code>opIfSgn</code></a></li>
<li><a href="#function-or"><code>or</code></a></li>
<li><a href="#function-product"><code>product</code></a></li>
<li><a href="#function-range"><code>range</code></a></li>
<li><a href="#function-reciprocal"><code>reciprocal</code></a></li>
<li><a href="#function-rtrim"><code>rtrim</code></a></li>
<li><a href="#function-sgn"><code>sgn</code></a></li>
<li><a href="#function-subtract"><code>subtract</code></a></li>
<li><a href="#function-sum"><code>sum</code></a></li>
<li><a href="#function-tail"><code>tail</code></a></li>
<li><a href="#function-trim"><code>trim</code></a></li>
<li><a href="#function-values"><code>values</code></a></li>
<li><a href="#function-xnor"><code>xnor</code></a></li>
<li><a href="#function-xor"><code>xor</code></a></li>
</ul>
<h4>Likely pure</h4>
<ul>
<li><a href="#function-arithmeticMean"><code>arithmeticMean</code></a></li>
<li><a href="#function-every"><code>every</code></a></li>
<li><a href="#function-everyProperty"><code>everyProperty</code></a></li>
<li><a href="#function-filter"><code>filter</code></a></li>
<li><a href="#function-filterProperties"><code>filterProperties</code></a></li>
<li><a href="#function-fThrow"><code>fThrow</code></a></li>
<li><a href="#function-geometricMean"><code>geometricMean</code></a></li>
<li><a href="#function-harmonicMean"><code>harmonicMean</code></a></li>
<li><a href="#function-ifElse"><code>ifElse</code></a></li>
<li><a href="#function-ifSgn"><code>ifSgn</code></a></li>
<li><a href="#function-map"><code>map</code></a></li>
<li><a href="#function-mapProperties"><code>mapProperties</code></a></li>
<li><a href="#function-median"><code>median</code></a></li>
<li><a href="#function-reduce"><code>reduce</code></a></li>
<li><a href="#function-reduceRight"><code>reduceRight</code></a></li>
<li><a href="#function-some"><code>some</code></a></li>
<li><a href="#function-someProperty"><code>someProperty</code></a></li>
</ul>
<h4>Unlikely pure</h4>
<ul>
<li><a href="#function-forEach"><code>forEach</code></a></li>
<li><a href="#function-forEachProperty"><code>forEachProperty</code></a></li>
<li><a href="#function-loop"><code>loop</code></a></li>
<li><a href="#function-tryCatch"><code>tryCatch</code></a></li>
<li><a href="#function-until"><code>until</code></a></li>
</ul>
<h4>Impure</h4>
<ul>
<li><a href="#function-activatePrototypeExtensions"><code>activatePrototypeExtensions</code></a></li>
<li><a href="#function-addMethod"><code>addMethod</code></a></li>
<li><a href="#function-inject"><code>inject</code></a></li>
<li><a href="#function-random"><code>random</code></a></li>
</ul>
</div>
</div>
</body>
</html>