Skip to content

Rename concatMap to something less scary #334

Closed

Description

@coffeemug

While concatMap is a descriptive name, it has a strange academic feel to it that confuses a lot people. We should find a nicer name (no doubt there is something clearer in the underscore.js/mongo world). emit, extract or something of the sort (I don't have a really good one, unfortunately)

Activity

  1. jdoliner commented on Feb 14, 2013

    @jdoliner
    Contributor

    Underscore has considered and refused to implement concatMap. They instead have a syntax I'm not too crazy about:

    _.chain(Customers)
      .map((customer) -> customer.orders()).flatten()
      .map((order) -> order.lineItems()).flatten()
      .value()
    

    In rethinkdb this would be:

    Customers.concatMap(r.row["orders"] + r.row["lineItems"])
    

    I can't find a mongo syntax for concatMap maybe I'm just missing it.

    Either way we need concat map because other crucial features desugar to it but we don't need to expose it to users if the name is too daunting.

  2. coffeemug commented on Feb 14, 2013

    @coffeemug
    ContributorAuthor

    To clarify what I meant, I agree that we need concatMap, I also think that we should keep it because it's awesome and not because we just need it, and I think we should make it available to users because it's actually very useful in dealing with arrays. I just think we should rename the function itself to something more palatable. Mongo people call (a much less powerful but roughly equivalent function) unwind which is an ok name, though I'm not too thrilled about it.

  3. jdoliner commented on Feb 14, 2013

    @jdoliner
    Contributor

    What about flatMap or flattenMap. That might be a bit more descriptive.

  4. coffeemug commented on Feb 14, 2013

    @coffeemug
    ContributorAuthor

    @al3xandru -- name thoughts?

  5. al3xandru commented on Feb 14, 2013

    @al3xandru
    Contributor

    flatMap

    (this also seems to be a function available in Scala)

  6. coffeemug commented on Feb 14, 2013

    @coffeemug
    ContributorAuthor

    Upon reflection, I actually really like unwind.

  7. al3xandru commented on Feb 14, 2013

    @al3xandru
    Contributor

    I think I've seen that used in Mongo and I had to look up what it means as unwind didn't tell me anything. The only other reference to unwind in APIs is in Cascading.

    I'm also thinking that we already have union for concatenating 2 sequences, so maybe this is a unionMap (?)

  8. al3xandru commented on Apr 1, 2013

    @al3xandru
    Contributor

    FWIW, I recently changed the API docs for concat_map to:

    Flattens a sequence of arrays returned by the mappingFunction into a single sequence.

    Run it by a couple of people and they found it very clear.

  9. mlucy commented on Apr 1, 2013

    @mlucy
    Member

    That actually seems mildly confusing to me. In most languages flatten is a recursive operation:

    irb(main):2076:0> [1, [2], [[3], [4]]].flatten
    [1, 2, 3, 4]

    Whereas concat_map just concatenates the returned arrays rather than recursing into them and flattening all the way down.

  10. mlucy commented on Apr 1, 2013

    @mlucy
    Member

    Also, just out of curiosity, are changes to the docs going through ccollab at this point?

  11. mglukhovsky commented on Apr 1, 2013

    @mglukhovsky
    Member

    Minor changes are over the shoulder, major changes are being reviewed by
    individual reviewers (to my understanding). You can also always see the
    history of YAML doc changes in GH.

    On Mon, Apr 1, 2013 at 3:16 PM, Michael Lucy [email protected]:

    Also, just out of curiosity, are changes to the docs going through ccollab
    at this point?

    —
    Reply to this email directly or view it on GitHubhttps://github.com//issues/334#issuecomment-15740819
    .

  12. al3xandru commented on Apr 1, 2013

    @al3xandru
    Contributor

    @mlucy since @coffeemug suggested using ccollab for all doc changes, all my changes are following the process.

  13. coffeemug commented on Jun 30, 2013

    @coffeemug
    ContributorAuthor

    Moving to 1.8, as this will become important for word counting example in map/reduce. Can we think of a better name for concatMap? Pinging @neumino, @mglukhovsky -- do you think concatMap is a good name? Can you think of anything better?

  14. neumino commented on Jun 30, 2013

    @neumino
    Member

    Did we have users complaining about concatMap being scary?

    I think it's fine. With our current API, I would more expect a syntax like that

    sequence.map().concat()
    

    I don't like unwind -- in the sense that I have no idea what it can do (with just the name)
    flatMap is fine, but I somehow prefer concatMap. To "flatten" is less common than "concat" (at least that's how I feel as a non native English speaker)

  15. coffeemug commented on Jul 1, 2013

    @coffeemug
    ContributorAuthor

    Nobody (that I remember) complained about concatMap, but I don't think people use the function often yet. This name seems confusing to me personally. In general, if we can come up with a good, descriptive single word name for this function, I'd like to do that. If we end up using a concatenation of two words (e.g. flatMap), I think we might as well use concatMap.

    To be clear, I don't think changing the name is a matter of adoption. Here is how I think about this. If we do our job well (and we have to assume we will, because otherwise the whole discussion becomes moot), in a year or two everyone will be using RethinkDB, and they'll be stuck with it for ten or fifteen years or more. Do we really want concatMap to be a part of that API? It seems like the worst named function in ReQL to me right now, and I'd like to think of something better if possible.

  16. 29 remaining items

  17. AtnNn commented on Dec 13, 2014

    @AtnNn
    Member

    This operation should not be called flatten. Flattening is an operation on trees (or recursive lists of lists). Here's an example from the Underscore documentation:

    _.flatten([1, [2], [3, [[4]]]]);
    => [1, 2, 3, 4];
    

    I personally like the names concat and concatMap

  18. danielmewes commented on Dec 13, 2014

    @danielmewes
    Member

    Here's a summary of most of the proposals made here. I might have missed some proposals and/or pros/cons. Please let me know if anything important is missing.

    Stick with concatMap

    • + compatibility
    • + "concat" isn't actually such a bad name probably

    flatMap()

    • + known from Scala

    flattenMap()

    map(... {multi: true})

    unwind() (or unwindMap?)

    • + known from MongoDB
    • - probably not as self-explanatory as some of the alternatives

    emit()

    unionMap()

    • + named consistently with our existing term union (unless there's a difference we haven't discussed here)

    Make it map().concat()

    Make it map().flatten()

  19. danielmewes commented on Dec 13, 2014

    @danielmewes
    Member

    We hadn't really discussed unionMap very much. Any additional thoughts on that?

  20. deontologician commented on Dec 13, 2014

    @deontologician
    Contributor

    I'd leave concatMap as it is, since the name is pretty standard, and add a recursive flatten term. I think if the major use case for this term moves to another term, (i.e. everyone takes all their array flattening business over to the flatten store), then concatMap is free to have a scary name since it'll only be used in odd circumstances.

    I don't see a lot of benefit to trying to make the name less general so it's easier to explain. It does exactly what's on the tin, it maps and concatenates.

  21. danielmewes commented on Dec 13, 2014

    @danielmewes
    Member

    @deontologician That sounds reasonable.
    So we could solve #3435 and probably some other use cases by introducing flatten. I guess it would be recursive by default, but we could add an opt arg to turn that off.

  22. thelinuxlich commented on Dec 13, 2014

    @thelinuxlich

    +1 for unionMap, for me it instantly made me understand what it does

  23. mlucy commented on Jan 15, 2015

    @mlucy
    Member

    I don't object strongly to union_map, but it's worth noting that while currently union concatenates streams, we've never explicitly promised that, and it would be more efficient in a lot of cases to intersperse elements from the different streams, so I could imagine a future in which union means "give me the elements from all of these streams in whatever way is most efficient" rather than "concatenate these streams".

    If we decide to commit to the current concatenation semantics for union, then union_map seems fine to me, and might be more obvious to people.

  24. danielmewes commented on Jan 20, 2015

    @danielmewes
    Member

    @mlucy that's a good point. I think especially with changefeeds we don't want to guarantee any particular ordering for union.

    I personally am tempted to close this and stick with concatMap, since none of the discussed alternatives seem to be without caveats.
    Does anyone still believe strongly that we should rename concatMap?

  25. coffeemug commented on Jan 21, 2015

    @coffeemug
    ContributorAuthor

    👍 for closing

  26. danielmewes commented on Jan 23, 2015

    @danielmewes
    Member

    I interpret the lack of protest as a no.
    Of course we can always re-open it later.

  27. briant5q commented on May 15, 2015

    @briant5q

    FWIW: I spent an hour today looking for the functionality that concatMap provides. However, coming from the MongoDB world, I was more familiar with the term 'unwind'. I wouldn't advocate changing the name at this point, but including the term "unwind" or "flatten" in the docs would help recovering MongoDB devs identify/google the term.

    In my case, I'm looking to map reduce on arrays of objects, which is often how unwind is used with Mongo. Might be helpful to include that use case some where in the docs, if it isn't already there.

  28. danielmewes commented on May 15, 2015

    @danielmewes
    Member

    Thanks for the feedback @briant5q
    @chipotle Do you think we could sneak those terms into the concat_map documentation? We could say something like
    "This operation is also known as "flattening" or "unwinding" the sequence."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions