duke-git / lancet

A comprehensive, efficient, and reusable util function library of Go.

Home Page:https://www.golancet.cn/en/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

stream Map Existing problem

lym169 opened this issue · comments

Currently, stream Map only supports conversions of the same type, but the practical application is more to map to different type slices
PixPin_2024-01-22_09-42-38

@lym169 This is because that go doesn't allow type parameters in methods. like below code snap:

func (s stream[T]) Map[U any](mapper func(item T) U) stream[U]

see https://www.reddit.com/r/golang/comments/tvfbow/the_fact_that_methods_are_not_allowed_to_have/
golang/go#49085

Thank you,
This can be done with interface{}, but ultimately you need to specify the type of conversion