implement Transform,TransformSlice,InsertAllFunc(#4,#16,#23)#56
implement Transform,TransformSlice,InsertAllFunc(#4,#16,#23)#56shoenig merged 3 commits intohashicorp:mainfrom
Conversation
72c70e2 to
d52bfcb
Compare
| // Transform transforms the set a into another set b | ||
| func Transform[T, E any](a CommonSet[T], b CommonSet[E], transform func(T) E) { | ||
| a.ForEach(func(item T) bool { | ||
| _ = b.Insert(transform(item)) | ||
| return true | ||
| }) | ||
| } |
There was a problem hiding this comment.
Would it be possible to have two versions of this function? One that transforms into an existing set like this implementation, but also one that creates the new set? e.g.
TransformUnion[T, E any](a CommonSet[T], b CommonSet[E], f func(T) E)Transform[T, E any](s CommonSet[T], f func(T) E) CommonSet[E]There was a problem hiding this comment.
I'm to rename transform as TransformUnion.
The other transform is not implemented for now, it may have to be implemented next time.
…on 4.rename: Transform to TransformUnion
| func Transform[T, E any](a Common[T], transform func(T) E, newSet func() Common[E]) Common[E] { | ||
| b := newSet() | ||
| TransformUnion(a, b, transform) | ||
| return b |
There was a problem hiding this comment.
Ahhh I didn't think of the newSet problem. Sorry to keep you going back and forth @zonewave, but can you remove Transform for now. I want to think if there's a cleaner way we can do this, without having to pass in a function to construct a new set. There's probably some generics magic + type switching we can do here, but I need time to think about it.
There was a problem hiding this comment.
actually, I also don't think it looks elegant.I have removed the last submission
Uh oh!
There was an error while loading. Please reload this page.