Permalink
Browse files

(!!) deprecate .get in favour of .unsafeGet (#42)

Closes #42
  • Loading branch information...
robotlolita committed Jan 7, 2017
1 parent 47a03dd commit 278d5a7a0fb612bb47501688dfebd6c79d92e0e8
Showing with 39 additions and 7 deletions.
  1. +39 −7 src/data/maybe/maybe.js
View
@@ -14,6 +14,7 @@ const assertType = require('folktale/helpers/assertType');
const assertFunction = require('folktale/helpers/assertFunction');
const { data, show, setoid, serialize } = require('folktale/core/adt');
const provideAliases = require('folktale/helpers/provide-fantasy-land-aliases');
const warnDeprecation = require('folktale/helpers/warnDeprecation');
/*~
@@ -133,12 +134,37 @@ Just.prototype.chain = function(transformation) {
// -- Extracting values and recovering ---------------------------------
// NOTE:
// `get` is similar to Comonad's `extract`. The reason we don't implement
// Comonad here is that `get` is partial, and not defined for Nothing
// values.
/*~
* ---
* category: Extracting values
* stability: deprecated
* type: |
* forall a: (Maybe a).() => a :: (throws TypeError)
*/
Nothing.prototype.get = function() {
warnDeprecation('`.get()` is deprecated, and has been renamed to `.unsafeGet()`.');
return this.unsafeGet();
};
/*~
* ---
* category: Extracting values
* stability: deprecated
* type: |
* forall a: (Maybe a).() => a :: (throws TypeError)
*/
Just.prototype.get = function() {
warnDeprecation('`.get()` is deprecated, and has been renamed to `.unsafeGet()`.');
return this.unsafeGet();
};
/*~
* ---
* category: Extracting values
* type: |
* forall a: (Maybe a).() => a :: (throws TypeError)
*/
Nothing.prototype.unsafeGet = function() {
throw new TypeError(`Can't extract the value of a Nothing.
Since Nothing holds no values, it's not possible to extract one from them.
@@ -147,9 +173,15 @@ that is not partial.
`);
};
Just.prototype.get = function() {
/*~
* ---
* category: Extracting values
* type: |
* forall a: (Maybe a).() => a :: (throws TypeError)
*/
Just.prototype.unsafeGet = function() {
return this.value;
};
}

0 comments on commit 278d5a7

Please sign in to comment.