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

Alias choose on Seq as flatMap (or flat_map or flatmap) #231

Open
vreuter opened this issue Nov 22, 2024 · 5 comments · Fixed by #235
Open

Alias choose on Seq as flatMap (or flat_map or flatmap) #231

vreuter opened this issue Nov 22, 2024 · 5 comments · Fixed by #235

Comments

@vreuter
Copy link
Contributor

vreuter commented Nov 22, 2024

IMO, "choose" sounds more like "filter", and I'd expect the argument to be a function like Callable[[A], bool]when dealing with a Seq[A], which then gives back the elements which satisfied the predicate. Or even some sort of randomised element selector. But what's really happening is each element in the collection is being mapped to an optional according to the passed function, and then the result is "flattened" back by collapsing down those wrapped structures to the original values, while discarding the empty values. One of the "flat map" variants thus feels more intuitive as a name, at least having it as an alias for the choose member of Seq. This would also match this pair of naming and behavior from e.g. Scala collections.

@dbrattli
Copy link
Owner

dbrattli commented Jan 8, 2025

Hi. The operator you are looking for is called collect.

@vreuter
Copy link
Contributor Author

vreuter commented Jan 9, 2025

Hi @dbrattli , I don't see it in the API docs for Seq; where is it defined?

@dbrattli
Copy link
Owner

Looks like the documentation is not being updated. I'll look into it this weekend.

@dbrattli dbrattli reopened this Jan 10, 2025
@neel-suthar
Copy link

Hey @dbrattli, I’ve been thinking about this, and I believe we should add an alias function called flat_map. It feels more natural and intuitive. What do you think?

@dbrattli
Copy link
Owner

dbrattli commented Mar 9, 2025

There is so many ways to name this function collect, select_many, bind, merge_map, map_merge, flat_map, ´concat_map. The more intuitive name would be map_merge` since it flattens after the transformation (map). But anyways, Expression tries to be consistent in the naming with F#, ref: https://fsharp.github.io/fsharp-core-docs/reference/fsharp-collections-seqmodule.html#collect

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 a pull request may close this issue.

3 participants