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

serialize: only first props? #3

Closed
jedahu opened this issue Feb 23, 2012 · 2 comments
Closed

serialize: only first props? #3

jedahu opened this issue Feb 23, 2012 · 2 comments

Comments

@jedahu
Copy link

jedahu commented Feb 23, 2012

Just curious. Why do the serialize methods take multiple props but only use the first one?

@pjt
Copy link
Owner

pjt commented Feb 23, 2012

Are you seeing a bug in practice, or asking based on the code?

If the latter, it may not be clear from context but the properties value there is a map from properties to values. It's an optional argument, so I use the & variable args construct: (defn f [& props] ... ), which means that in the body of the function props is actually bound to a seq with one item. Calling first simply extracts the map from the seq.

Another way to handle this case is with destructuring: (defn f [& [props]] ... ) in which case props will be bound to the first item passed, not to the seq created by the ampersand.

@jedahu
Copy link
Author

jedahu commented Feb 23, 2012

I was asking based on the code, mainly because I've written a serialize-to-string function and wanted to be sure of your intent. Personally I prefer the destructuring option because it makes it clear the function takes only one additional argument, but each to their own :-).

@jedahu jedahu closed this as completed Feb 23, 2012
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

No branches or pull requests

2 participants