Skip to content

Allow zero argument form of concatMap #3435

Open

Description

@deontologician

The most common usage of concatMap for me is to simply flatten a sequence. It'd be nice if there were a zero-argument form that assumes a default of the id function so thatconcatMap() is equivalent to concatMap{|x| x}

Activity

  1. danielmewes commented on Dec 12, 2014

    @danielmewes
    Member

    I think that's a good idea. I would suggest we do it together with #334 .

  2. added this to the subsequent milestone on Dec 12, 2014
  3. mlucy commented on Dec 13, 2014

    @mlucy
    Member

    I'm not 100% sure about this, since no other terms that take a function default to the identity function if one isn't provided. (Although, thinking about it, the convention would make sense for filter too; seq.filter would mean "remove all instances of false and nil from the sequence".)

    Another option would be to introduce a flatten term.

  4. deontologician commented on Dec 13, 2014

    @deontologician
    ContributorAuthor

    tbh, the flatten term would probably be nicer/more explicit. This just happens because I want the concat but don't need the map and it's kinda verbose.

  5. deontologician commented on Dec 13, 2014

    @deontologician
    ContributorAuthor

    I think empty args means identity would work for most terms that require a function, but most of them would be kinda useless.

  6. modified the milestones: 2.1, subsequent, on Mar 23, 2015
  7. modified the milestones: subsequent, on Apr 17, 2015
  8. segphault commented on May 6, 2015

    @segphault

    👍

    I recently ran into a situation where I used concatMap to combine a bunch of arrays into a single array:

    r.expr([{items: [1,2,3]}, {items: [4,5,6]}])("items").concatMap(function(x) { return x })
    

    I think it would make sense to be able to use concatMap without an argument to achieve the desired outcome.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions