File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -5,18 +5,13 @@ class Either {
55}
66
77class Left extends Either {
8- get isLeft ( ) {
9- return true
10- }
11- get isRight ( ) {
12- return false
13- }
14- // ----- Functor (Either a)
15- map ( ) {
16- return this
17- }
18- join ( ) {
19- return this
8+ constructor ( x ) {
9+ super ( x )
10+ this . isLeft = true
11+ this . isRight = false
12+ // ----- Functor (Either a)
13+ this . map = ( ) => this
14+ this . join = ( ) => this
2015 }
2116 // ----- Applicative (Either a)
2217 // ap() { return this }
@@ -29,18 +24,14 @@ class Left extends Either {
2924}
3025
3126class Right extends Either {
32- get isLeft ( ) {
33- return false
34- }
35- get isRight ( ) {
36- return true
37- }
38- // ----- Functor (Either a)
39- map ( fn ) {
40- return Either . of ( fn ( this . $value ) )
41- }
42- join ( ) {
43- return this . $value
27+ constructor ( x ) {
28+ super ( x )
29+ this . $value = x
30+ this . isLeft = false
31+ this . isRight = true
32+ // ----- Functor (Either a)
33+ this . map = fn => Either . of ( fn ( x ) )
34+ this . join = ( ) => this . $value
4435 }
4536 // ----- Applicative (Either a)
4637 // ap(f) { return f.map(this.$value) }
Original file line number Diff line number Diff line change 11class Identity {
22 constructor ( x ) {
3- this . $value = x
4- }
5- // ----- Functor Identity
6- map ( fn ) {
7- return Identity . of ( fn ( this . $value ) )
8- }
9- // ----- Monad Identity
10- chain ( fn ) {
11- return this . map ( fn ) . join ( )
12- }
13- join ( ) {
14- return this . $value
3+ // ----- Functor Identity
4+ this . map = fn => Identity . of ( fn ( x ) )
5+ // ----- Monad Identity
6+ this . chain = fn => this . map ( fn ) . join ( )
7+ this . join = ( ) => x
158 }
169 // inspect() { return `Identity(${this.$value})` }
1710 // ----- Applicative Identity
Original file line number Diff line number Diff line change 11class Maybe {
2- get nil ( ) {
3- return this . $value === undefined
4- }
52 constructor ( x ) {
63 this . $value = x
7- }
8- // ----- Functor Maybe
9- map ( fn ) {
10- return this . nil ? this : Maybe . of ( fn ( this . $value ) )
11- }
12- join ( ) {
13- return this . nil ? this : this . $value
4+ this . nil = x === undefined
5+ // ----- Functor Maybe
6+ this . map = fn => ( this . nil ? this : Maybe . of ( fn ( x ) ) )
7+ this . join = ( ) => ( this . nil ? this : x )
148 }
159 // inspect() { return `Maybe(${this.$value}`; }
1610 // ----- Applicative Maybe
You can’t perform that action at this time.
0 commit comments