You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: readme.md
+18-15Lines changed: 18 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -75,6 +75,7 @@ __Table of Contents__
75
75
*[Option](#option)
76
76
*[Function](#function)
77
77
*[Partial function](#partial-function)
78
+
*[Dealing with partial functions](#dealing-with-partial-functions)
78
79
*[Functional Programming Libraries in JavaScript](#functional-programming-libraries-in-javascript)
79
80
80
81
@@ -121,7 +122,7 @@ This allows the values in the closure to be accessed by returned functions.
121
122
122
123
```js
123
124
constaddTo=x=>y=> x + y
124
-
var addToFive =addTo(5)
125
+
constaddToFive=addTo(5)
125
126
addToFive(3) // => 8
126
127
```
127
128
@@ -179,7 +180,6 @@ curriedSum(40)(2) // 42.
179
180
constadd2=curriedSum(2) // (b) => 2 + b
180
181
181
182
add2(10) // 12
182
-
183
183
```
184
184
185
185
## Auto Currying
@@ -372,12 +372,15 @@ class Max {
372
372
constructor (a) {
373
373
this.a= a
374
374
}
375
+
375
376
id () {
376
377
returnthis
377
378
}
379
+
378
380
compose (b) {
379
381
returnthis.a>b.a?this: b
380
382
}
383
+
381
384
toString () {
382
385
return`Max(${this.a})`
383
386
}
@@ -396,7 +399,7 @@ Anything that can be assigned to a variable.
396
399
397
400
```js
398
401
5
399
-
Object.freeze({name:'John', age:30}) // The `freeze` function enforces immutability.
402
+
Object.freeze({name:'John', age:30}) // The `freeze` function enforces immutability.
400
403
;(a) => a
401
404
;[1]
402
405
undefined
@@ -408,15 +411,15 @@ A variable that cannot be reassigned once defined.
408
411
409
412
```js
410
413
constfive=5
411
-
constjohn=Object.freeze({name:'John', age:30})
414
+
constjohn=Object.freeze({name:'John', age:30})
412
415
```
413
416
414
417
Constants are [referentially transparent](#referential-transparency). That is, they can be replaced with the values that they represent without affecting the result.
415
418
416
419
With the above two constants the following expression will always return `true`.
417
420
418
421
```js
419
-
john.age+ five === ({name:'John', age:30}).age+(5)
422
+
john.age+ five === ({name:'John', age:30}).age+5
420
423
```
421
424
422
425
### Constant Function
@@ -434,15 +437,15 @@ const constant = a => () => a
434
437
Object whose `map` doesn't transform the contents. See [Functor](#functor)
435
438
436
439
```js
437
-
Constant(1).map(n=> n +1) // => Constant(1)
440
+
Constant(1).map(n=> n +1) // => Constant(1)
438
441
```
439
442
440
443
### Constant Monad
441
444
442
445
Object whose `chain` doesn't transform the contents. See [Monad](#monad)
@@ -581,7 +584,7 @@ A branch of mathematics that uses functions to create a [universal model of comp
581
584
Lazy evaluation is a call-by-need evaluation mechanism that delays the evaluation of an expression until its value is needed. In functional languages, this allows for structures like infinite lists, which would not normally be available in an imperative language where the sequencing of commands is significant.
582
585
583
586
```js
584
-
constrand=function*() {
587
+
constrand=function*() {
585
588
while (1<2) {
586
589
yieldMath.random()
587
590
}
@@ -742,13 +745,13 @@ For example, 2D coordinates could be stored as an array `[2,3]` or object `{x: 2
742
745
743
746
```js
744
747
// Providing functions to convert in both directions makes them isomorphic.
0 commit comments