Skip to content

ReQL proposal: unsplit command #1147

Open

Description

@coffeemug

Currently there are many commands missing on strings that are present on arrays. Until we get around to filling out the string API, we should allow coercing to arrays and back as an option to do things like slice:

r.expr('foo').coerceTo('array') // ['f', 'o', 'o']
r.expr(['f', 'o', 'o']).coerceTo('string') // 'foo'

Activity

  1. jdoliner commented on Jul 8, 2013

    @jdoliner
    Contributor

    What's returned by:

    ["fo" ,"o"].coerceTo('string')
    
  2. mlucy commented on Jul 8, 2013

    @mlucy
    Member

    Currently r.expr(['f', 'o', 'o']).coerceTo('string') will print it as JSON.

  3. coffeemug commented on Jul 8, 2013

    @coffeemug
    ContributorAuthor

    What's returned by: ["fo" ,"o"].coerceTo('string')

    Err, I didn't think of this. The obvious option is 'foo', though introduction of this edge case suggests others like ['f', 1, 'o'] which may or may not throw a wrench into this proposal.

    Currently r.expr(['f', 'o', 'o']).coerceTo('string') will print it as JSON.

    Err. May be we shouldn't do this then. People can just call reduce instead, which seems like a sufficient workaround.

  4. neumino commented on Jul 8, 2013

    @neumino
    Member

    Does reduce guaranty to give back a string with the characters in a good order?
    My guess is in this case yes, but it's going to be confusing for some people.

  5. coffeemug commented on Jul 8, 2013

    @coffeemug
    ContributorAuthor

    I'm just full of holes today. Heh.

  6. srh commented on May 20, 2017

    @srh
    Contributor

    str.coerceTo('array') can be done with str.split(''). Closing.

  7. modified the milestones: wontfix, backlog on May 20, 2017
  8. marshall007 commented on May 20, 2017

    @marshall007
    Contributor

    @srh perhaps we should reopen #5336? I think r.expr(['f', 'o', 'o']).coerceTo('string') is still a pretty valid and common use-case, but implementing it as .coerceTo('string') is not very discoverable.

    I'd also be satisfied with something like r.expr(['f', 'o', 'o']).reduce(r.add), but that relies on a resolution to #1320. In my PR #5673 (comment) it was suggested that this be done server-side.

  9. srh commented on Jun 13, 2017

    @srh
    Contributor

    You could do r.add(r.args(['f', 'o', 'o'])). I think there should be a string join function though. The question is, what should it be named in a database engine?

  10. thelinuxlich commented on Jun 13, 2017

    @thelinuxlich

    Maybe r.concat?

  11. srh commented on Jun 13, 2017

    @srh
    Contributor

    Apparently I was wrong about split because it does crazy stuff with combining characters, such as combining them. Reopening.

  12. reopened this on Jun 13, 2017
  13. modified the milestones: , wontfix on Jun 13, 2017
  14. srh commented on Jun 13, 2017

    @srh
    Contributor

    Maybe we could call it unsplit, because concat sounds related to concatMap, or vice versa. r.expr(":").unsplit(["foo", "bar"]) => "foo:bar". (And join is obviously a bad idea.)

  15. thelinuxlich commented on Jun 13, 2017

    @thelinuxlich

    Unsplit is good

  16. marshall007 commented on Jun 13, 2017

    @marshall007
    Contributor

    Yea, I like unsplit too, but I think the string separator argument should be second and optional. I would have said the separator argument should default to , but since .split() defaults to "splitting on whitespace" I'm not sure what we should do.

  17. srh commented on Jun 14, 2017

    @srh
    Contributor

    Maybe the separator should be second, but not optional. Or (evil option) the default character should be a zero-width space. But only when r.now() is April 1st.

  18. srh commented on Jun 14, 2017

    @srh
    Contributor

    My serious inclination is to have the separator be second, default value is the empty string. So .unsplit() just concatenates strings.

  19. marshall007 commented on Jun 14, 2017

    @marshall007
    Contributor

    @srh yep, sounds good. That's how I wish .split() behaved, but by default it splits on all whitespace. It would seem reasonable that <string>.split().unsplit() == <string>, but unfortunately that will not always be the case.

  20. gabor-boros commented on May 28, 2022

    @gabor-boros
    Member

    @srh Reading through the thread about, the title could be "ReQL proposal: unsplit command" since it is more about implementing that rather than extending coercions, right?

  21. changed the title [-]Support `string.coerceTo('array')` and `array.coerceTo('string')`[/-] [+]ReQL proposal: `unsplit` command[/+] on Nov 5, 2026
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

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions