5 ms·
Don't know Scala, but I'd assume that `+:` is prepend to list and `:+` is append to list.
by talideon 10y ago
Don't know Scala, but I'd assume that `+:` is prepend to list and `:+` is append to list.
- rvense 10y agoYou'd be correct. But they're just method calls, both defined on the class of l. It is a little weird.
- jfb 10y agoI can see the argument for terseness in source, particularly in domains where the terseness in code reflects well-understood shorthand in the actual problem space. But stuff like that makes me itch, to be honest.
- rvense 10y agoThe alternative would be something like l.prepend(a).append(b) Horrible. Ghastly. Can't see anybody tolerating a language that looked like that.. /s
- jfb 10y agoWhat? Mutating a list? DISGUSTING!
- speedkills 10y agoIt's not mutating, its returning a new list with elements prepended and appended.
- yawaramin 10y agoIt gets even worse. Because Scala has infix syntax for method calls, you can do l prepend a append b
- snoman 10y agoDon't know Scala but why wouldn't it be a.append(l).append(b) ?
- rvense 10y agoThat would only work if a was itself a list..