44 lines
1.2 KiB
JavaScript
44 lines
1.2 KiB
JavaScript
"use strict";
|
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const freeze_js_1 = __importDefault(require("./freeze.js"));
|
|
/**
|
|
* Returns a function that always returns the supplied value.
|
|
*
|
|
* Useful for replacing an object outright rather than merging it.
|
|
*
|
|
* @function
|
|
* @sig a -> (* -> a)
|
|
* @memberOf u
|
|
* @param {*} value what to return from returned function.
|
|
* @return {function} a new function that will always return value.
|
|
*
|
|
* @example
|
|
* var alwaysFour = u.constant(4);
|
|
* expect(alwaysFour(32)).toEqual(4);
|
|
*
|
|
* @example
|
|
* var user = {
|
|
* name: 'Mitch',
|
|
* favorites: {
|
|
* band: 'Nirvana',
|
|
* movie: 'The Matrix'
|
|
* }
|
|
* };
|
|
*
|
|
* var newFavorites = {
|
|
* band: 'Coldplay'
|
|
* };
|
|
*
|
|
* var result = u({ favorites: u.constant(newFavorites) }, user);
|
|
*
|
|
* expect(result).toEqual({ name: 'Mitch', favorites: { band: 'Coldplay' } });
|
|
*/
|
|
function constant(value) {
|
|
const frozen = (0, freeze_js_1.default)(value);
|
|
return () => frozen;
|
|
}
|
|
exports.default = constant;
|
|
//# sourceMappingURL=constant.js.map
|