Skip to content

Commit

Permalink
Release v0.9.0
Browse files Browse the repository at this point in the history
See the readme for changes
  • Loading branch information
uniphil committed Oct 27, 2015
1 parent 6aa14d0 commit 4fc2750
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 34 deletions.
46 changes: 14 additions & 32 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,6 @@ function Union(options) {
}

var maybeProto = {
_promote: function _promote(value) {
if (value instanceof Maybe.OptionClass) {
return value;
} else {
return Maybe.Some(value);
}
},
isSome: function isSome() {
return this.name === 'Some';
},
Expand Down Expand Up @@ -221,16 +214,16 @@ var maybeProto = {
return this.name === 'Some' ? Promise.resolve(this.data) : Promise.reject(fn());
},
and: function and(other) {
return this.name === 'Some' ? this._promote(other) : this;
return this.name === 'Some' ? Maybe.Some(other) : this;
},
andThen: function andThen(fn) {
return this.name === 'Some' ? this._promote(fn(this.data)) : this;
return this.name === 'Some' ? Maybe.Some(fn(this.data)) : this;
},
or: function or(other) {
return this.name === 'Some' ? this : this._promote(other);
return this.name === 'Some' ? this : Maybe.Some(other);
},
orElse: function orElse(fn) {
return this.name === 'Some' ? this : this._promote(fn());
return this.name === 'Some' ? this : Maybe.Some(fn());
}
};

Expand All @@ -242,8 +235,8 @@ var maybeStatic = {
all: function all(values) {
return values.reduce(function (res, next) {
return res.andThen(function (resArr) {
return maybeProto._promote(next).andThen(function (v) {
return Maybe.Some(resArr.concat(v));
return Maybe.Some(next).andThen(function (v) {
return resArr.concat(v);
});
});
}, Maybe.Some([]));
Expand All @@ -257,8 +250,7 @@ var Maybe = Union({
if (name === 'Some') {
return function (value) {
if (value instanceof UnionOptionClass) {
var unwrapped = value.unwrapOr(); // Some's value or Undefined
return new UnionOptionClass(options, 'Some', unwrapped);
return value;
} else {
return new UnionOptionClass(options, 'Some', value);
}
Expand All @@ -272,13 +264,6 @@ var Maybe = Union({
});

var resultProto = {
_promote: function _promote(value) {
if (value instanceof Result.OptionClass) {
return value;
} else {
return Result.Ok(value);
}
},
isOk: function isOk() {
return this.name === 'Ok';
},
Expand All @@ -298,16 +283,16 @@ var resultProto = {
return this.name === 'Ok' ? Promise.reject(this.data) : Promise.resolve(this.data);
},
and: function and(other) {
return this.name === 'Ok' ? this._promote(other) : this;
return this.name === 'Ok' ? Result.Ok(other) : this;
},
andThen: function andThen(fn) {
return this.name === 'Ok' ? this._promote(fn(this.data)) : this;
return this.name === 'Ok' ? Result.Ok(fn(this.data)) : this;
},
or: function or(other) {
return this.name === 'Ok' ? this : this._promote(other);
return this.name === 'Ok' ? this : Result.Ok(other);
},
orElse: function orElse(fn) {
return this.name === 'Ok' ? this : this._promote(fn(this.data));
return this.name === 'Ok' ? this : Result.Ok(fn(this.data));
},
unwrapOr: function unwrapOr(def) {
return this.name === 'Ok' ? this.data : def;
Expand Down Expand Up @@ -345,8 +330,8 @@ var resultStatic = {
all: function all(values) {
return values.reduce(function (res, next) {
return res.andThen(function (resArr) {
return resultProto._promote(next).andThen(function (v) {
return Result.Ok(resArr.concat(v));
return Result.Ok(next).andThen(function (v) {
return resArr.concat(v);
});
});
}, Result.Ok([]));
Expand All @@ -360,10 +345,7 @@ var Result = Union({
if (name === 'Ok') {
return function (value) {
if (value instanceof UnionOptionClass) {
var unwrapped = value.unwrapOrElse(function (e) {
return e;
});
return new UnionOptionClass(options, 'Ok', unwrapped);
return value;
} else {
return new UnionOptionClass(options, 'Ok', value);
}
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "results",
"version": "0.8.0",
"description": "Rust-inspired Result and Option tools for javascript",
"version": "0.9.0",
"description": "Discriminated Unions including Maybe (an option type) and Result for javascript with fewer bugs",
"main": "index.js",
"scripts": {
"gulp": "gulp",
Expand All @@ -15,11 +15,13 @@
"Rust",
"Result",
"Option",
"Maybe",
"Some",
"None",
"Ok",
"Err",
"Enum",
"Union",
"Match"
],
"contributors": [
Expand Down
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,8 @@ Changes
### v0.9.0
2015-10-27
#### Breaking
* **Result.Ok(value)** now **returns** `value` if it is an instance of
Expand Down

0 comments on commit 4fc2750

Please sign in to comment.