import L from "lodash" ; type StringGen = string | ( ( ) => string ) ; export function flatMap < T , U > ( arr , f ) { const r = [ ] ; for ( const x of arr ) { r . push ( ... f ( x ) ) ; } return r ; } export function ensure < T > ( x , msg = "" ) { if ( x === null || x === undefined ) { debugger ; msg = ( L . isString ( msg ) ? msg : msg ( ) ) || "" ; throw new Error ( `Value must not be undefined or null${ msg ? `- ${ msg }` : "" }` ) ; } else { return x ; } } export function ensureString ( x ) { if ( L . isString ( x ) ) { return x ; } else { throw new Error ( `Expected ${ x } to be a string` ) ; } } export class AssertionError extends Error { constructor ( msg = "Assertion failed" ) { super ( msg ) ; } } export function assert < T > ( cond , msg = "Assertion failed" ) { if ( ! cond ) { msg = ( L . isString ( msg ) ? msg : msg ( ) ) || "Assertion failed" ; debugger ; throw new AssertionError ( msg ) ; } } export const tuple = < T extends any [ ] > ( ... args ) : T => args ;