You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
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.
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.
@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.
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?
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.)
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.
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.
@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.
@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?
Activity
jdoliner commentedon Jul 8, 2013
What's returned by:
mlucy commentedon Jul 8, 2013
Currently
r.expr(['f', 'o', 'o']).coerceTo('string')will print it as JSON.coffeemug commentedon Jul 8, 2013
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.Err. May be we shouldn't do this then. People can just call
reduceinstead, which seems like a sufficient workaround.neumino commentedon Jul 8, 2013
Does
reduceguaranty 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.
coffeemug commentedon Jul 8, 2013
I'm just full of holes today. Heh.
srh commentedon May 20, 2017
str.coerceTo('array') can be done with str.split(''). Closing.
marshall007 commentedon May 20, 2017
@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.srh commentedon Jun 13, 2017
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?thelinuxlich commentedon Jun 13, 2017
Maybe r.concat?
srh commentedon Jun 13, 2017
Apparently I was wrong about
splitbecause it does crazy stuff with combining characters, such as combining them. Reopening.srh commentedon Jun 13, 2017
Maybe we could call it
unsplit, becauseconcatsounds related toconcatMap, or vice versa.r.expr(":").unsplit(["foo", "bar"])=>"foo:bar". (Andjoinis obviously a bad idea.)thelinuxlich commentedon Jun 13, 2017
Unsplit is good
marshall007 commentedon Jun 13, 2017
Yea, I like
unsplittoo, 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.srh commentedon Jun 14, 2017
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.
srh commentedon Jun 14, 2017
My serious inclination is to have the separator be second, default value is the empty string. So
.unsplit()just concatenates strings.marshall007 commentedon Jun 14, 2017
@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.gabor-boros commentedon May 28, 2022
@srh Reading through the thread about, the title could be "ReQL proposal:
unsplitcommand" since it is more about implementing that rather than extending coercions, right?[-]Support `string.coerceTo('array')` and `array.coerceTo('string')`[/-][+]ReQL proposal: `unsplit` command[/+]