Skip to content

Commit 62c7507

Browse files
committed
isNothing => nil
1 parent 752abd6 commit 62c7507

2 files changed

Lines changed: 8 additions & 11 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ exclaim('hey') // -> HEY!
188188

189189
## Bonus
190190
Dependencies: None!<br>
191-
Size: <1KB gzipped
191+
Size: <2KB gzipped
192192

193193
## Examples
194194
See [/examples](https://github.com/mfix22/morphmorph/tree/master/examples) or [`test/index.spec.js`](https://github.com/mfix22/morphmorph/tree/master/test/index.spec.js) for many examples of how to use `MorphMorph`.

src/maybe.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,30 @@
11
class Maybe {
2-
get isNothing() {
3-
return this.$value === null || this.$value === undefined
4-
}
5-
get isJust() {
6-
return !this.isNothing
2+
get nil() {
3+
return this.$value == null
74
}
85
constructor(x) {
96
this.$value = x
107
}
118
// ----- Functor Maybe
129
map(fn) {
13-
return this.isNothing ? this : Maybe.of(fn(this.$value))
10+
return this.nil ? this : Maybe.of(fn(this.$value))
1411
}
1512
join() {
16-
return this.isNothing ? this : this.$value
13+
return this.nil ? this : this.$value
1714
}
1815
// inspect() { return `Maybe(${this.$value}`; }
1916
// ----- Applicative Maybe
20-
// ap(f) { return this.isNothing ? this : f.map(this.$value) }
17+
// ap(f) { return this.nil ? this : f.map(this.$value) }
2118
// ----- Monad Maybe
2219
// chain(fn) { return this.map(fn).join() }
2320
// ----- Traversable Maybe
2421
// sequence(of) { this.traverse(of, identity) }
25-
// traverse(of, fn) { return this.isNothing ? of(this) : fn(this.$value).map(Maybe.of) }
22+
// traverse(of, fn) { return this.nil ? of(this) : fn(this.$value).map(Maybe.of) }
2623
}
2724
// ----- Pointed Maybe
2825
Maybe.of = x => new Maybe(x)
2926

30-
const maybe = v => f => m => (m.isNothing ? v : f(m.$value))
27+
const maybe = v => f => m => (m.nil ? v : f(m.$value))
3128

3229
module.exports = {
3330
Maybe,

0 commit comments

Comments
 (0)