import { Exponent } from "./generated/exponent" ; export function getExponentValue ( value ) { return parseInt ( value , 10 ) ; } export const negateExponent = ( value ) => toExponent ( - getExponentValue ( value ) ) ; export const addExponents = wrapBinaryExponentFn ( ( left , right ) => left + right ) ; export const multiplyExponents = wrapBinaryExponentFn ( ( left , right ) => left * right ) ; export const divideExponents = wrapBinaryExponentFn ( ( left , right ) => left / right ) ; type BinaryExponentFn = ( left : Exponent , right : Exponent ) => Exponent ; function wrapBinaryExponentFn ( fn ) { return ( left , right ) => toExponent ( fn ( getExponentValue ( left ) , getExponentValue ( right ) ) ) ; } function toExponent ( value ) { return `${ value }` as Exponent ; }