Convert string to labelled option argument


#1

I’m working on a query parser and I’m wondering if it’s possible to send a parsed string as a labelled arguments. So for example if we have
"?id=5"

then the query parser would parse “id” and the value 5. Would it be possible then to convert that to send it in as a labelled argument for a function so that f(~id=5)? and if the string wouldn’t match any arguments then it would be ignored.


#2

The closest I can think of is to make id an optional labelled parameter, then parse id from the query string as an optional value. Then you directly pass it into the function: f(?id, ...)


#3

Wouldn’t order matter then? If we have something like

"/books?author=M&year=2019

then if order matter we have to ensure that author goes as the first argument and then year as the second. Which means that we have to sort in the parser. If we can send in the labelled argument author=M then that would mean no manual sorting is needed.