thoas / go-funk

A modern Go utility library which provides helpers (map, find, contains, filter, ...)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Accept pointers to iteratees

zasran opened this issue · comments

It would be great if everywhere an iteratee was needed (i.e. IsIteratee(i) must be true) it also accepted a pointer to such iteratee. It's a less frequent but very useful use case.

Example use case: input is a reflect type and JSON which encodes a slice of the given type. Create a pointer to a slice of the given type dynamically, use json.Unmarshal to populate it. At this point it would be great to be able to use funk.Map directly instead of having to use reflect to dereference the pointer like this reflect.ValueOf(slicePtr).Elem().Interface(), after all that's the whole point of funk, to simplify the code that deals with various Go data structures.

Code example https://goplay.space/#0GUn6UbxvJR (see locally defined Map).

Not sure what's the best way to implement this within funk, maybe GetIteratee instead of IsIteratee to hide the code dealing with dereferencing the pointer?

If there is an agreed upon way to do it I would probably be able to submit PR.

commented

closing this issue

It would be useful to know why was this closed. Is there a reason not to implement it? Do you just not have the time to implement it?

I'd probably be able to submit a patch, just not sure what's the best way to implement it. Is GetIteratee acceptable way to go ?