What does “:+” mean in Scala
up vote
8
down vote
favorite
I saw some Scala code written as:
def next(): Array[String] = someVariable.next() :+ iterator.key
Where someVariable
has a method next()
to get the next line and the iterator is of type Iterator[String]
.
What does :+
mean here?
scala
add a comment |
up vote
8
down vote
favorite
I saw some Scala code written as:
def next(): Array[String] = someVariable.next() :+ iterator.key
Where someVariable
has a method next()
to get the next line and the iterator is of type Iterator[String]
.
What does :+
mean here?
scala
1
Is there some reason why you didn't just look this up in the scala doc? scala-lang.org/api/2.11.8/… The API documentation is fairly comprehensive, and my "go to" place for questions like this.
– The Archetypal Paul
May 12 '16 at 15:23
It's cool new docs (2.12) give you this nice search feature scala-lang.org/files/archive/api/2.12.0-M4/index.html?search=:+
– mfirry
May 12 '16 at 20:12
@TheArchetypalPaul the time you took to write this stuff, could have answered him in a better way...
– AZ_
May 16 at 20:12
add a comment |
up vote
8
down vote
favorite
up vote
8
down vote
favorite
I saw some Scala code written as:
def next(): Array[String] = someVariable.next() :+ iterator.key
Where someVariable
has a method next()
to get the next line and the iterator is of type Iterator[String]
.
What does :+
mean here?
scala
I saw some Scala code written as:
def next(): Array[String] = someVariable.next() :+ iterator.key
Where someVariable
has a method next()
to get the next line and the iterator is of type Iterator[String]
.
What does :+
mean here?
scala
scala
edited May 12 '16 at 15:57
Peter Neyens
8,6341429
8,6341429
asked May 12 '16 at 14:56
jlp
4091822
4091822
1
Is there some reason why you didn't just look this up in the scala doc? scala-lang.org/api/2.11.8/… The API documentation is fairly comprehensive, and my "go to" place for questions like this.
– The Archetypal Paul
May 12 '16 at 15:23
It's cool new docs (2.12) give you this nice search feature scala-lang.org/files/archive/api/2.12.0-M4/index.html?search=:+
– mfirry
May 12 '16 at 20:12
@TheArchetypalPaul the time you took to write this stuff, could have answered him in a better way...
– AZ_
May 16 at 20:12
add a comment |
1
Is there some reason why you didn't just look this up in the scala doc? scala-lang.org/api/2.11.8/… The API documentation is fairly comprehensive, and my "go to" place for questions like this.
– The Archetypal Paul
May 12 '16 at 15:23
It's cool new docs (2.12) give you this nice search feature scala-lang.org/files/archive/api/2.12.0-M4/index.html?search=:+
– mfirry
May 12 '16 at 20:12
@TheArchetypalPaul the time you took to write this stuff, could have answered him in a better way...
– AZ_
May 16 at 20:12
1
1
Is there some reason why you didn't just look this up in the scala doc? scala-lang.org/api/2.11.8/… The API documentation is fairly comprehensive, and my "go to" place for questions like this.
– The Archetypal Paul
May 12 '16 at 15:23
Is there some reason why you didn't just look this up in the scala doc? scala-lang.org/api/2.11.8/… The API documentation is fairly comprehensive, and my "go to" place for questions like this.
– The Archetypal Paul
May 12 '16 at 15:23
It's cool new docs (2.12) give you this nice search feature scala-lang.org/files/archive/api/2.12.0-M4/index.html?search=:+
– mfirry
May 12 '16 at 20:12
It's cool new docs (2.12) give you this nice search feature scala-lang.org/files/archive/api/2.12.0-M4/index.html?search=:+
– mfirry
May 12 '16 at 20:12
@TheArchetypalPaul the time you took to write this stuff, could have answered him in a better way...
– AZ_
May 16 at 20:12
@TheArchetypalPaul the time you took to write this stuff, could have answered him in a better way...
– AZ_
May 16 at 20:12
add a comment |
2 Answers
2
active
oldest
votes
up vote
17
down vote
accepted
:+
is a method on whatever type is returned by someVariable.next()
.
Presumably it's scala.Array.:+
A copy of this array with an element appended.
This is also a case where an IDE would help you greatly. With Intellij for example, you could use the "Quick doc" or "Jump to definition" commands on :+
and immediately find out where it came from. I've found that tooling to be invaluable in writing scala.
Thank you very much!
– jlp
May 12 '16 at 15:07
add a comment |
up vote
16
down vote
On Scala Collections there is usually :+
and +:
.
Both add an element to the collection. :+
appends +:
prepends.
A good reminder is, :
is where the Collection goes.
There is as well colA ++: colB
to concat collections, where the :
side collection determines the resulting type.
But there is no :++
that would be just colA ++ colB
where the result has the type of colA
.
Very comprehensive and concise, thanks!
– suvayu
Oct 9 '17 at 11:00
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
17
down vote
accepted
:+
is a method on whatever type is returned by someVariable.next()
.
Presumably it's scala.Array.:+
A copy of this array with an element appended.
This is also a case where an IDE would help you greatly. With Intellij for example, you could use the "Quick doc" or "Jump to definition" commands on :+
and immediately find out where it came from. I've found that tooling to be invaluable in writing scala.
Thank you very much!
– jlp
May 12 '16 at 15:07
add a comment |
up vote
17
down vote
accepted
:+
is a method on whatever type is returned by someVariable.next()
.
Presumably it's scala.Array.:+
A copy of this array with an element appended.
This is also a case where an IDE would help you greatly. With Intellij for example, you could use the "Quick doc" or "Jump to definition" commands on :+
and immediately find out where it came from. I've found that tooling to be invaluable in writing scala.
Thank you very much!
– jlp
May 12 '16 at 15:07
add a comment |
up vote
17
down vote
accepted
up vote
17
down vote
accepted
:+
is a method on whatever type is returned by someVariable.next()
.
Presumably it's scala.Array.:+
A copy of this array with an element appended.
This is also a case where an IDE would help you greatly. With Intellij for example, you could use the "Quick doc" or "Jump to definition" commands on :+
and immediately find out where it came from. I've found that tooling to be invaluable in writing scala.
:+
is a method on whatever type is returned by someVariable.next()
.
Presumably it's scala.Array.:+
A copy of this array with an element appended.
This is also a case where an IDE would help you greatly. With Intellij for example, you could use the "Quick doc" or "Jump to definition" commands on :+
and immediately find out where it came from. I've found that tooling to be invaluable in writing scala.
edited May 12 '16 at 15:25
answered May 12 '16 at 15:01
Daenyth
23.7k862103
23.7k862103
Thank you very much!
– jlp
May 12 '16 at 15:07
add a comment |
Thank you very much!
– jlp
May 12 '16 at 15:07
Thank you very much!
– jlp
May 12 '16 at 15:07
Thank you very much!
– jlp
May 12 '16 at 15:07
add a comment |
up vote
16
down vote
On Scala Collections there is usually :+
and +:
.
Both add an element to the collection. :+
appends +:
prepends.
A good reminder is, :
is where the Collection goes.
There is as well colA ++: colB
to concat collections, where the :
side collection determines the resulting type.
But there is no :++
that would be just colA ++ colB
where the result has the type of colA
.
Very comprehensive and concise, thanks!
– suvayu
Oct 9 '17 at 11:00
add a comment |
up vote
16
down vote
On Scala Collections there is usually :+
and +:
.
Both add an element to the collection. :+
appends +:
prepends.
A good reminder is, :
is where the Collection goes.
There is as well colA ++: colB
to concat collections, where the :
side collection determines the resulting type.
But there is no :++
that would be just colA ++ colB
where the result has the type of colA
.
Very comprehensive and concise, thanks!
– suvayu
Oct 9 '17 at 11:00
add a comment |
up vote
16
down vote
up vote
16
down vote
On Scala Collections there is usually :+
and +:
.
Both add an element to the collection. :+
appends +:
prepends.
A good reminder is, :
is where the Collection goes.
There is as well colA ++: colB
to concat collections, where the :
side collection determines the resulting type.
But there is no :++
that would be just colA ++ colB
where the result has the type of colA
.
On Scala Collections there is usually :+
and +:
.
Both add an element to the collection. :+
appends +:
prepends.
A good reminder is, :
is where the Collection goes.
There is as well colA ++: colB
to concat collections, where the :
side collection determines the resulting type.
But there is no :++
that would be just colA ++ colB
where the result has the type of colA
.
edited Jan 29 at 16:23
answered May 12 '16 at 15:29
Nabil A.
2,7271124
2,7271124
Very comprehensive and concise, thanks!
– suvayu
Oct 9 '17 at 11:00
add a comment |
Very comprehensive and concise, thanks!
– suvayu
Oct 9 '17 at 11:00
Very comprehensive and concise, thanks!
– suvayu
Oct 9 '17 at 11:00
Very comprehensive and concise, thanks!
– suvayu
Oct 9 '17 at 11:00
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f37190619%2fwhat-does-mean-in-scala%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Is there some reason why you didn't just look this up in the scala doc? scala-lang.org/api/2.11.8/… The API documentation is fairly comprehensive, and my "go to" place for questions like this.
– The Archetypal Paul
May 12 '16 at 15:23
It's cool new docs (2.12) give you this nice search feature scala-lang.org/files/archive/api/2.12.0-M4/index.html?search=:+
– mfirry
May 12 '16 at 20:12
@TheArchetypalPaul the time you took to write this stuff, could have answered him in a better way...
– AZ_
May 16 at 20:12