Closed dray92 closed 2 years ago
My personal preference is to have the code accepting the data to handle the conversion, so in the case of ToSlice(), it's pretty easy for your application to do a type assertion or switch statement, so I think that's on you.
for _, el := range set.ToSlice() {
thing := el.(string)
switch el.(type) {
case string:
#
}
}
On the other hand, converting your application's slices into interface slices as you describe for NewSetFromSlice
is pretty annoying. I resolved this in the above PR by accepting an interface rather than a slice of interfaces and sorting it out with the reflection library, which was already included by the threadUnsafeSet.
Closing due to no activity on this.
Currently, methods like ToSlice() return a slice of interface objs, which makes sense.
In practice, we find ourselves having to write multiple helpers to go from interface slices to primitives like strings, int, etc., whether it be for using
NewSetFromSlice
, orToSlice
.Is value in added a set of helpers under the
mapset
package to support transformations between core primitive types, andinterface{}
?(I am happy to contribute.)