From 4fc2750a6f2fa8c7fa09fbc36b64b33557a6bb50 Mon Sep 17 00:00:00 2001 From: phil Date: Tue, 27 Oct 2015 13:33:10 -0400 Subject: [PATCH] Release v0.9.0 See the readme for changes --- index.js | 46 ++++++++++++++-------------------------------- package.json | 6 ++++-- readme.md | 2 ++ 3 files changed, 20 insertions(+), 34 deletions(-) diff --git a/index.js b/index.js index 37b94dd..08cb320 100644 --- a/index.js +++ b/index.js @@ -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'; }, @@ -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()); } }; @@ -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([])); @@ -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); } @@ -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'; }, @@ -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; @@ -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([])); @@ -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); } diff --git a/package.json b/package.json index 645cf03..8829893 100644 --- a/package.json +++ b/package.json @@ -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", @@ -15,11 +15,13 @@ "Rust", "Result", "Option", + "Maybe", "Some", "None", "Ok", "Err", "Enum", + "Union", "Match" ], "contributors": [ diff --git a/readme.md b/readme.md index 7dc68ba..281e1a1 100644 --- a/readme.md +++ b/readme.md @@ -607,6 +607,8 @@ Changes ### v0.9.0 +2015-10-27 + #### Breaking * **Result.Ok(value)** now **returns** `value` if it is an instance of