Skip to content

Proposal: array-to-string (opposite of split) #5336

Closed

Description

@mike-marcacci

Hi there! I'm looking to join an array of strings into one string using a delimiter (the exact inverse of split) to this effect:

r.expr('foo:bar:baz').split(':').join('.');
// => "foo.bar.baz"

I feel like I must be missing something, but the best solution I've come up with breaks if reduce is parallelized.

This works, and probably always will:

r.expr('foo:bar:baz').split(':').reduce((l,r) => l.add('.').add(r));
// => "foo.bar.baz"

But this might not:

r.table('sequence').orderBy({index: 'weight'})('value').reduce((l,r) => l.add(':').add(r));

While I don't really have a use case for the latter, it makes me uncomfortable to use a RQL reduce function that makes an assumption of order. Another option might be to add an option argument to reduce that could accept {parallel: false}, although I imagine that would be a bit more work to write, and a join or concat string method would be nice for symmetry.

Activity

  1. mlucy commented on Jan 29, 2016

    @mlucy
    Member

    @mike-marcacci -- Thanks for opening this! We'll be adding a fold term (#3736) in RethinkDB 2.3 that will let you do a reduce-like operation that's guaranteed to be applied in a particular order. Closing as a duplicate of that issue.

  2. mike-marcacci commented on Jan 30, 2016

    @mike-marcacci
    Author

    Wonderful! I hadn't seen that issue - thanks!

  3. added this to the duplicate milestone on Feb 16, 2017
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions