Quantcast
Channel: ReScript Forum - Latest posts
Viewing all articles
Browse latest Browse all 2592

Need help with binding to a function with a complex type

$
0
0

hey, thanks you for letting me know about the tag decorator, that’s really nice to know.

i’m kinda confused about the parameterType, because with the way you’re showcasing it in the code, it doesn’t seem like there’s a way to get out the actual parameters after running the function, so for example, if i do this

let par = Utils.parseParametersFromArguments([{name: "index", type_: Number}], args)

this returns a parseResult and i can match on it but if i match on it, in the success i only get a dict of parameter types with seemingly no payload.

i really appreciate you for helping, and it would be really awesome if you could show me how i could modify this to make it possible to then do something like

    switch par {
    | Success({parameters}) => {
        let index = parameters->Js.Dict.get("index")

        switch index {
        | Some(i) => switch i {
          | Number(asd) => %todo
          | _ => %todo
          }
        | None => %todo
        }
      }
    | Failure(_) => {}
    }

(btw, if you put the type as Number into the function it’s guaranteed that it’s either gonna return a javascript number or fail to parse, resulting in a Failure)

((by returning a javascript number i mean that running the js code

utils.parseParametersFromArguments([{name: "index", type: "number"}, {name: "foo", type: "string"}], ["index:123"])

results in this object

{ "success": true, "parameters": { "index": 123 }, "args": [] }

and doing this

utils.parseParametersFromArguments([{name: "index", type: "number"}, {name: "foo", type: "string"}], ["index:asd"])
{ "success": false, "reply": "Could not parse parameter \"index\"!" }

Viewing all articles
Browse latest Browse all 2592

Trending Articles