2023-01-03 18:51:35 +00:00
|
|
|
import freeze from "./freeze.js";
|
2015-08-19 14:29:06 +00:00
|
|
|
/**
|
|
|
|
* 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' } });
|
|
|
|
*/
|
2023-01-03 18:51:35 +00:00
|
|
|
export default function constant(value) {
|
|
|
|
const frozen = freeze(value);
|
|
|
|
return () => frozen;
|
2015-08-13 05:19:04 +00:00
|
|
|
}
|
2023-01-03 18:51:35 +00:00
|
|
|
//# sourceMappingURL=constant.js.map
|