From fc95253dd5046d2938208ed1370771c93407a202 Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Thu, 14 Jul 2022 15:15:03 -0700 Subject: [PATCH] Cleanup of Dict Fromlist in Function Registry Library --- .../FunctionRegistry_Library.res | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/packages/squiggle-lang/src/rescript/FunctionRegistry/FunctionRegistry_Library.res b/packages/squiggle-lang/src/rescript/FunctionRegistry/FunctionRegistry_Library.res index efb8d584..6fa23892 100644 --- a/packages/squiggle-lang/src/rescript/FunctionRegistry/FunctionRegistry_Library.res +++ b/packages/squiggle-lang/src/rescript/FunctionRegistry/FunctionRegistry_Library.res @@ -506,6 +506,21 @@ module Dict = { ->E.A2.fmap(((key, value)) => Wrappers.evArray([IEvString(key), value])) ->Wrappers.evArray + let fromList = (items: array): result< + internalExpressionValue, + string, + > => + items + ->E.A2.fmap(item => { + switch (item: internalExpressionValue) { + | IEvArray([IEvString(string), value]) => (string, value)->Ok + | _ => Error(impossibleError) + } + }) + ->E.A.R.firstErrorOrOpen + ->E.R2.fmap(Belt.Map.String.fromArray) + ->E.R2.fmap(Wrappers.evRecord) + let merge = (a: t, b: t): internalExpressionValue => IEvRecord( Belt.Map.String.merge(a, b, (_, _, c) => c), ) @@ -621,22 +636,11 @@ module Dict = { ~requiresNamespace=true, ~name="fromList", ~inputs=[FRTypeArray(FRTypeArray(FRTypeAny))], - ~run=(_, inputs, _) => { - let convertInternalItems = items => - items - ->E.A2.fmap(item => { - switch item { - | [FRValueString(string), value] => - (string, FunctionRegistry_Core.FRType.matchReverse(value))->Ok - | _ => Error(impossibleError) - } - }) - ->E.A.R.firstErrorOrOpen - ->E.R2.fmap(Belt.Map.String.fromArray) - ->E.R2.fmap(Wrappers.evRecord) - inputs->getOrError(0)->E.R.bind(Prepare.ToValueArray.Array.arrayOfArrays) - |> E.R2.bind(convertInternalItems) - }, + ~run=(inputs, _, _) => + switch inputs { + | [IEvArray(items)] => Internals.fromList(items) + | _ => Error(impossibleError) + }, (), ), ],