-
Notifications
You must be signed in to change notification settings - Fork 50
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
fluent: provide an API to convert an ipld.Node to a generic Go value #178
Comments
Also, I'm intentionally avoiding the name bikeshedding until we agree that we want this. |
Agree useful. Agree it would allocate a lot for large structures, and agree we should also just document that and say use it at your own (performance) risk. Agree that it would return |
This would also let us bang out some interesting quick tests and examples like: take a dag-json fixture; parse to ... not that anyone would ever really need to do that, but the example could be helpful for showing people what these concepts can be compared to. |
What about going the same route as json et. al. with |
That's what @mvdan's also doing in the new It's also just much less code involved to do an unpack into (Standard library golang json even has a special path when it notices it's unpacking into |
I'll take this @mvdan, can you assign this to me please? |
In other words, the reverse of
fluent.Reflect
.Int
gives anint64
,Map
gives amap[string]interface{}
,List
gives a[]interface{}
, and so on.This is somewhat similar to how code-generated scalar nodes have methods like
Int() int64
as well as the usualAsInt() (int64, error)
, but applied more generally for any node implementation and kind.The main use case is when one has small IPLD nodes, such as any scalar kind or a small list/map, and one wants to obtain the plain Go value for easy use. Especially for debugging or testing, too.
This could potentially allocate a lot for large maps or lists, but we assume noone would do that.
Unfortunately this does mean that calling this API on a
List_String
would return a[]interface{}
instead of[]string
, which is unfortunate and not terribly helpful. But I don't think we can reasonably do better right now. Perhaps we can revisit that with generics.cc @warpfork @willscott for the recent discussion
cc @gammazero since your recent question made me reconsider proposing this
The text was updated successfully, but these errors were encountered: