Innovenergy_trunk/frontend/node_modules/fp-ts/lib/struct.js

90 lines
2.8 KiB
JavaScript
Raw Normal View History

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.evolve = exports.getAssignSemigroup = void 0;
/**
* @since 2.10.0
*/
var _ = __importStar(require("./internal"));
// -------------------------------------------------------------------------------------
// instances
// -------------------------------------------------------------------------------------
/**
* Return a semigroup which works like `Object.assign`.
*
* @example
* import { getAssignSemigroup } from 'fp-ts/struct'
*
* interface Person {
* readonly name: string
* readonly age: number
* }
*
* const S = getAssignSemigroup<Person>()
* assert.deepStrictEqual(S.concat({ name: 'name', age: 23 }, { name: 'name', age: 24 }), { name: 'name', age: 24 })
*
* @category instances
* @since 2.10.0
*/
var getAssignSemigroup = function () { return ({
concat: function (first, second) { return Object.assign({}, first, second); }
}); };
exports.getAssignSemigroup = getAssignSemigroup;
// -------------------------------------------------------------------------------------
// utils
// -------------------------------------------------------------------------------------
/**
* Creates a new object by recursively evolving a shallow copy of `a`, according to the `transformation` functions.
*
* @example
* import { pipe } from 'fp-ts/function'
* import { evolve } from 'fp-ts/struct'
*
* assert.deepStrictEqual(
* pipe(
* { a: 'a', b: 1 },
* evolve({
* a: (a) => a.length,
* b: (b) => b * 2
* })
* ),
* { a: 1, b: 2 }
* )
*
* @since 2.11.0
*/
var evolve = function (transformations) {
return function (a) {
var out = {};
for (var k in a) {
if (_.has.call(a, k)) {
out[k] = transformations[k](a[k]);
}
}
return out;
};
};
exports.evolve = evolve;