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

Add EncodeConvert to implementation #1

Open
hypirion opened this issue Sep 28, 2015 · 0 comments
Open

Add EncodeConvert to implementation #1

hypirion opened this issue Sep 28, 2015 · 0 comments
Milestone

Comments

@hypirion
Copy link
Member

We have edn.AddTagFn and edn.AddTagStruct which makes it possible to convert any tagged EDN value into any untagged value.

edn.EncodeConvert would complement edn.AddTagFn, taking in a function of one argument that returns two arguments: The value to actually encode, and an error if something went wrong.

edn.EncodeAsTag would complement edn.AddTagStruct in the same fashion.

In this way, people can use other people's libraries without having to make wrapper types for every type they export. For example, attaching a definition for time.Time would look like this:

edn.EncodeConvert(func(t time.Time) (edn.Tag, error) {
    return edn.Tag{"inst", t.Format(time.RFC3339Nano)}, nil
})
@hypirion hypirion added this to the 1.1 milestone Sep 30, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant