Skip to content
New issue

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

Update FlatMap docs to talk about nil case #314

Merged
merged 1 commit into from
Mar 20, 2023
Merged

Update FlatMap docs to talk about nil case #314

merged 1 commit into from
Mar 20, 2023

Conversation

jlaneve
Copy link
Contributor

@jlaneve jlaneve commented Feb 23, 2023

One interesting use case of FlatMap that isn't intuitively obvious from the docs is the ability to return nil. For example,

var key = map[string][]string{"a": ["b","c"], "d": ["e","f"]}
var myKeys = []string{"a","c","d","g"}

lo.FlatMap(key, func(s string, _ int) []string { return key[s] })
// returns []string{"b","c","e","f"}

The docs should explicitly mention what happens if you return nil, so a user would be able to deduce this use case themselves.

@samber samber merged commit e2be213 into samber:master Mar 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants