kevinmost
11/24/2017, 4:12 PM.copy
to allocate a new instancedimsuz
11/24/2017, 4:13 PMWell you can't generically call copy, so you're always dealing with a concrete data class type, so you know whether you need to call copy or not.I know, but I mean that compiler could generate a
copy
which is smart enough to not copy when current value is equal to the new onedimsuz
11/24/2017, 4:14 PMI'd expect any call to .copy to allocate a new instanceUsually when you working with an immutable data you don't rely on reference equality, but rely on
equals()
instead, so it wouldn't matterdimsuz
11/24/2017, 4:14 PMkevinmost
11/24/2017, 4:19 PMval v2 = if (v1.v == 1) v1 else v1.copy(v = 1)
I do see your point but I think the stdlib and language in general was designed to be lean and orthogonal and let you do exactly what you want with their building blocks, not provide an exact feature for everything everyone might wantdimsuz
11/24/2017, 4:24 PMdimsuz
11/24/2017, 4:24 PMcopy
- doing manual checks becomes tedioius...kevinmost
11/24/2017, 4:25 PMdimsuz
11/24/2017, 4:26 PMdimsuz
11/24/2017, 4:26 PMdimsuz
11/24/2017, 4:27 PMarocnies
12/02/2017, 4:12 AMelect
12/02/2017, 8:52 AM[0...x]
to retrieve a substring from a String?evanchooly
12/02/2017, 4:21 PMkarelpeeters
12/02/2017, 4:31 PMevanchooly
12/02/2017, 4:53 PMelect
12/02/2017, 6:30 PMelect
12/02/2017, 6:39 PMilya.gorbunov
12/02/2017, 7:28 PMslice
function which you can use with ranges:
string.slice(from..toInclusive)
uli
12/02/2017, 10:31 PMkevinmost
12/03/2017, 12:13 AMsubstring
function (I guess now there's slice
which would be better). Is there a reason that it's not already implemented as an operator? It seems very expressive to me what str[0..3]
would doevanchooly
12/03/2017, 12:16 AMraulraja
12/03/2017, 12:25 AMraulraja
12/03/2017, 12:27 AMString?
it'd be useful otherwise it may have to throw an exception if out of range.kevinmost
12/03/2017, 12:27 AMkevinmost
12/03/2017, 12:27 AMstring.slice(0..3)
does anyway?kevinmost
12/03/2017, 12:28 AMoperator fun String.get(range: IntRange) = slice(range)
raulraja
12/03/2017, 12:30 AMkarelpeeters
12/05/2017, 4:51 PMkarelpeeters
12/05/2017, 4:51 PM