I would like do something like this inline function in go, and don't want to write a for loop...
const userIds = Users.map(u => u.Id);
I would like do something like this inline function in go, and don't want to write a for loop...
const userIds = Users.map(u => u.Id);
I suggest using a package named go-funk to manupulate array/slice. It may look like lodash in some aspects Your code may look like this:
userIds := funk.Map(Users, func(u structTypeOfUser) int {
return u.Id
}).([]int);
It supports many other familiar functions like find, reduce, filter, contains(include)...
Repository of that package:
https://github.com/thoas/go-funk