Merge branch 'develop' of https://github.com/skejeton/squiggle into sampleset-fix-error-message
This commit is contained in:
commit
a48efc23b0
|
@ -10,6 +10,8 @@ let examples = E.A.to_list(FunctionRegistry_Core.Registry.allExamples(registry))
|
||||||
|
|
||||||
describe("FunctionRegistry Library", () => {
|
describe("FunctionRegistry Library", () => {
|
||||||
describe("Regular tests", () => {
|
describe("Regular tests", () => {
|
||||||
|
testEvalToBe("List.length([3,5,8])", "Ok(3)")
|
||||||
|
testEvalToBe("List.length([])", "Ok(0)")
|
||||||
testEvalToBe("List.make(3, 'HI')", "Ok(['HI','HI','HI'])")
|
testEvalToBe("List.make(3, 'HI')", "Ok(['HI','HI','HI'])")
|
||||||
testEvalToBe("make(3, 'HI')", "Error(make is not defined)")
|
testEvalToBe("make(3, 'HI')", "Error(make is not defined)")
|
||||||
testEvalToBe("List.upTo(1,3)", "Ok([1,2,3])")
|
testEvalToBe("List.upTo(1,3)", "Ok([1,2,3])")
|
||||||
|
|
|
@ -5,6 +5,10 @@ let nameSpace = "List"
|
||||||
let requiresNamespace = true
|
let requiresNamespace = true
|
||||||
|
|
||||||
module Internals = {
|
module Internals = {
|
||||||
|
let length = (v: array<Reducer_T.value>): Reducer_T.value => IEvNumber(
|
||||||
|
Belt.Int.toFloat(Array.length(v)),
|
||||||
|
)
|
||||||
|
|
||||||
let makeFromNumber = (n: float, value: Reducer_T.value): Reducer_T.value => IEvArray(
|
let makeFromNumber = (n: float, value: Reducer_T.value): Reducer_T.value => IEvArray(
|
||||||
Belt.Array.make(E.Float.toInt(n), value),
|
Belt.Array.make(E.Float.toInt(n), value),
|
||||||
)
|
)
|
||||||
|
@ -75,6 +79,26 @@ module Internals = {
|
||||||
}
|
}
|
||||||
|
|
||||||
let library = [
|
let library = [
|
||||||
|
Function.make(
|
||||||
|
~name="length",
|
||||||
|
~nameSpace,
|
||||||
|
~output=EvtNumber,
|
||||||
|
~requiresNamespace=true,
|
||||||
|
~examples=[`List.length([1,4,5])`],
|
||||||
|
~definitions=[
|
||||||
|
FnDefinition.make(
|
||||||
|
~name="length",
|
||||||
|
~inputs=[FRTypeArray(FRTypeAny)],
|
||||||
|
~run=(inputs, _, _) =>
|
||||||
|
switch inputs {
|
||||||
|
| [IEvArray(array)] => Internals.length(array)->Ok
|
||||||
|
| _ => Error(impossibleError)
|
||||||
|
},
|
||||||
|
(),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
(),
|
||||||
|
),
|
||||||
Function.make(
|
Function.make(
|
||||||
~name="make",
|
~name="make",
|
||||||
~nameSpace,
|
~nameSpace,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user