Skip to content

Commit

Permalink
(!!) deprecate .get in favour of .unsafeGet (#42)
Browse files Browse the repository at this point in the history
Closes #42
  • Loading branch information
robotlolita committed Jan 7, 2017
1 parent 47a03dd commit 278d5a7
Showing 1 changed file with 39 additions and 7 deletions.
46 changes: 39 additions & 7 deletions src/data/maybe/maybe.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');


/*~
Expand Down Expand Up @@ -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.
Expand All @@ -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;
};
}



Expand Down

0 comments on commit 278d5a7

Please sign in to comment.