We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
m := lo. PickByKeys(map[string]int{"foo": 1, "bar": 2, "baz": 3}, []string{"foo", "baz"}) // []int{1,3}
The output values' order should be the same as the input slice.
Assume we have a list of openids:
openids = []string{openid1, openid2}
Then we have a method to transfer it into user_id:
func ToUserIDs(openids []string) map[string]string{}
The output of ToUserIDs is a map, in which the key is openid and the value is UserID.
ToUserIDs
If I call Values, then i would get a unordered list, which can not keep the original order with openids
Values
openids
So maybe we need one "Ordered PickByKeys function that returns a slice"?
Further more, the method could support the following scene:
gourpA := []string{openid1, openid2, openid3} gourpB := []string{openid4, openid5, openid6} gourpC := []string{openid7, openid8, openid9} all := append([]string{}, gourpA...) all := append(all, gourpB...) all := append(all, gourpC...) users := fetchUsers(all) usersA := lo.PickByKeys(users, gourpA) usersB := lo.PickByKeys(users, gourpB) usersC := lo.PickByKeys(users, gourpC)
Join all the IDs, fetch in one request, then separate the returned entities into different groups.
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Example
The output values' order should be the same as the input slice.
Why we need it
Assume we have a list of openids:
Then we have a method to transfer it into user_id:
The output of
ToUserIDs
is a map, in which the key is openid and the value is UserID.If I call
Values
, then i would get a unordered list, which can not keep the original order withopenids
So maybe we need one "Ordered PickByKeys function that returns a slice"?
Further more, the method could support the following scene:
Join all the IDs, fetch in one request, then separate the returned entities into different groups.
The text was updated successfully, but these errors were encountered: