Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow functional expansion #9

Closed
tfausak opened this issue Apr 18, 2020 · 1 comment · Fixed by #10
Closed

Allow functional expansion #9

tfausak opened this issue Apr 18, 2020 · 1 comment · Fixed by #10

Comments

@tfausak
Copy link
Owner

tfausak commented Apr 18, 2020

It should be possible to provide a function, or perhaps a monadic action, to replace variables with their values. That way you could look them up from the environment, read them from the database, or have them depend on the current time.

There is one small wrinkle here from section 3.2.1:

If a variable appears more than once in an expression or within multiple expressions of a URI Template, the value of that variable MUST remain static throughout the expansion process (i.e., the
variable must have the same value for the purpose of calculating each expansion). However, if reserved characters or pct-encoded triplets occur in the value, they will be pct-encoded by some expression types and not by others.

So when replacing in this manner, each value must be requested at most once.

@tfausak
Copy link
Owner Author

tfausak commented Apr 19, 2020

The expandTemplate function already kind of allows this:

expandTemplate
:: Applicative m
=> (Name.Name -> m (Maybe Value.Value))
-> Template.Template
-> m String

I think the constraint would have to change to Monad m in order to cache lookups, but otherwise that should work nicely.

@tfausak tfausak mentioned this issue May 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant