UNPKG

@harmoniclabs/plu-ts-onchain

Version:

An embedded DSL for Cardano smart contracts creation coupled with a library for Cardano transactions, all in Typescript

32 lines (31 loc) 869 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getFnTypes = void 0; var type_system_1 = require("../../type_system/index.js"); /** * given a term type of a function (lambda) * extracts all the types from the inputs to the output * * the last type is the final output of the funciton. * * * @example * ```ts * const notFn = getFnTypes( int ); // [ int ]; * const simleLam = getFnTypes( lam( int, bs ) ); // [ int, bs ]; * const twoIns = getFnTypes( fn([ int, str ], bs ) ); // [ int, str, bs ]; * ``` * * @param {TermType} fnT function term type * @returns {TermType[]} */ function getFnTypes(fnT) { var result = []; while (fnT[0] === type_system_1.PrimType.Lambda) { result.push(fnT[1]), fnT = fnT[2]; } result.push(fnT); return result; } exports.getFnTypes = getFnTypes;