-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(bettermath): Add ref support to lazy evaluation of values, depen…
…ding on external ref-value maps
- Loading branch information
1 parent
fb1e057
commit f9bf92f
Showing
13 changed files
with
354 additions
and
129 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,20 @@ | ||
import type { Index } from "parsimmon"; | ||
import { Types } from "../../definitions"; | ||
import { IBaseType, Types, ValueResolvingResult } from "../../definitions"; | ||
import { FunctionType, IFunctionArg } from "../types"; | ||
|
||
export class ConcatFunction extends FunctionType<string> { | ||
readonly returnType = Types.STRING; | ||
constructor(indexInfo: Index, args: IFunctionArg<string | number>[]) { | ||
constructor(indexInfo: Index, args: (IFunctionArg<string> | IFunctionArg<number>)[]) { | ||
super(indexInfo, "CONCAT", args); | ||
} | ||
|
||
getValue = () => this.args.reduce((acc, arg) => acc + arg.getValue(), ""); | ||
getValue = (dependencyValueMap: Map<string, IBaseType<any> | undefined>) => { | ||
try { | ||
return ValueResolvingResult.success( | ||
this.args.reduce((acc, arg) => acc + arg.getValue(dependencyValueMap).getOrElse(""), "") | ||
) | ||
} catch (e) { | ||
return ValueResolvingResult.error<string>(e as Error) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { ValueResolvingResult } from "../../definitions" | ||
|
||
export const resolveValuesOnlyNumbers = <T>(values: ValueResolvingResult<T>[]) => { | ||
|
||
const anyError = values.find(val => val.isError) | ||
|
||
if (anyError) { | ||
throw anyError.getError() | ||
} | ||
|
||
const resolvedValues = values.map(result => result.get()) | ||
if (resolvedValues.some(val => !Number.isFinite(val))) { | ||
throw new Error("Arguments must be numbers.") | ||
} | ||
|
||
return resolvedValues | ||
} |
Oops, something went wrong.