RFC: should startsWith and endsWith work with characters? #4252

Closed
abudden opened this Issue Jun 1, 2016 · 1 comment

Projects

None yet

2 participants

@abudden
Contributor
abudden commented Jun 1, 2016

From a consistency perspective, it seems logical to me that you can do this:

doAssert "abc".startsWith("a") # works
doAssert "abc".endsWith("c") # works
doAssert "abc".startsWith('a') # compile error
doAssert "abc".endsWith('c') # compile error

The latter can easily be achieved with:

doAssert "abc"[0] == 'a'
var s = "abc"
doAssert s[s.high] == 'c'

however, this feels a bit more messy to me and doesn't as obviously show the intention.

@dom96
Member
dom96 commented Jun 3, 2016

Yeah, make a PR please :)

@abudden abudden added a commit to abudden/Nim that referenced this issue Jun 6, 2016
@abudden abudden Added startsWith/endsWith implementations for character prefix/suffix…
… (fixes #4252).
d8480c7
@Araq Araq closed this in #4282 Jun 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment