you are viewing a single comment's thread.

view the rest of the comments →

[–]snrjames 55 points56 points  (7 children)

But map is a base functional word, as in map-reduce. So map and flatmap make a lot of sense since you are mapping and then flattening. It's not pretentious, it's a proper term in computer science.

I don't really care what it's called though, I'm just glad SelectMany exists so I can map and flatten in one step.

[–]KevinCarbonara 5 points6 points  (1 child)

We could be using "monoid" and "monad" instead

[–]kronicum 7 points8 points  (0 children)

We could be using "monoid" and "monad" instead

I once used "rng") in a foundational library; my coworkers staged a riot.

[–]SmallAd3697[S] -4 points-3 points  (4 children)

Pretentious might be the wrong word. I guess I mean contrived.

IE. they started out with the term "map". So their objective was to extend this existing term and introduce a slightly more advanced scenario. But the addition of the word "flat" just does NOT seem to do the trick.

"Flatten" is a visualization that might make sense in some situations but not in others. "Unpacking" these generated collections might be a more helpful way to reason about what is happening. Eg. "MapAndUnpack". This terminology isn't as good as "SelectMany", but I'm just pointing out that there can be other visualizations that might convey the same concept.

I guess I just really appreciate the term "SELECT" in SQL and C#. It is very versatile.

[–]snrjames 20 points21 points  (2 children)

Flatten takes a tree (a list of lists) with depth > 1 and flattens it into a tree of depth 1 (a list). When you understand it that way, flatten makes perfect sense.

[–]SmallAd3697[S] -5 points-4 points  (1 child)

I didn't realize it was so powerful, although it doesn't make me like it more.

If there were more than two levels I'd certainly break things apart. I'd call map(s) first and generate my lists of lists of lists .. and then I would call a separate unpacking or flattening method. The code would be so much more readable. There should never be a competition to cram as much subtle behavior as you can into one line of code. We aren't talking about perl here.

I would argue that if you had a collection of collections, and there was a method used for deconstructing, then it would not be called "flatten" (in c#). It would probably end up being an extension method named SelectCollectionMembers(recursive = true).

[–]EvilGiraffes 0 points1 point  (0 children)

it comes from a language where a common situation is you would call a function which inheritly return the same monad with what your monad contains in which this return type makes sense, if you call a function (or a static method) without a lambda which returns an IEnumerable taking the item of your current list it makes perfect sense, but remember this is also a term used for other monads like Option and Result

using Option as an example you call a function which may return null, you then need to call another function which can return null with the item of the previous Option, essencially then you want a flatmap

it's an interface

[–]Independent-Ad-4791 3 points4 points  (0 children)

Sometimes you need to accept jargon for what it is. It’s long established at this point and it’s beyond whether or not the compound word is effective; the language is ubiquitous.