Groups
Groups
Sign in
Groups
Groups
golang-nuts
Conversations
About
Send feedback
Help
x/exp/slices: add Map/Extract function
291 views
Skip to first unread message
cpu...@gmail.com
unread,
Mar 20, 2022, 1:14:15 PM
3/20/22
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to golang-nuts
Playing with 1.18 I've noticed that I can immediately replace pretty much all uses of
https://github.com/thoas/go-funk
with the new slices package.
One common use case that I happen to have in the codebase quite a lot is extracting data from a slice of objects:
funk.Map(chargers, func(c easee.Charger)
string
{ return c.ID })
I feel it would be nice to add something like that as part of slices:
func Map[From, To any](s []From, f func(From) To) []To {
res := make([]To, len(s))
for i, v := range s {
res[i] = f(v)
}
return res
}
Has this already been discussed?
Thanks,
Andi
Carla Pfaff
unread,
Mar 20, 2022, 1:29:04 PM
3/20/22
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to golang-nuts
On Sunday, 20 March 2022 at 18:14:15 UTC+1
cpu...@gmail.com
wrote:
Has this already been discussed?
Yes:
https://github.com/golang/go/discussions/47203#discussioncomment-1005237
Reply all
Reply to author
Forward
0 new messages