What does “:+” mean in Scala











up vote
8
down vote

favorite
4












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?










share|improve this question




















  • 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















up vote
8
down vote

favorite
4












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?










share|improve this question




















  • 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













up vote
8
down vote

favorite
4









up vote
8
down vote

favorite
4






4





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?










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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














  • 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












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.






share|improve this answer























  • Thank you very much!
    – jlp
    May 12 '16 at 15:07


















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.






share|improve this answer























  • Very comprehensive and concise, thanks!
    – suvayu
    Oct 9 '17 at 11:00











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















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

























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.






share|improve this answer























  • Thank you very much!
    – jlp
    May 12 '16 at 15:07















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.






share|improve this answer























  • Thank you very much!
    – jlp
    May 12 '16 at 15:07













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.






share|improve this answer














:+ 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.







share|improve this answer














share|improve this answer



share|improve this answer








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


















  • 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












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.






share|improve this answer























  • Very comprehensive and concise, thanks!
    – suvayu
    Oct 9 '17 at 11:00















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.






share|improve this answer























  • Very comprehensive and concise, thanks!
    – suvayu
    Oct 9 '17 at 11:00













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.






share|improve this answer














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.







share|improve this answer














share|improve this answer



share|improve this answer








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


















  • 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


















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

404 Error Contact Form 7 ajax form submitting

How to know if a Active Directory user can login interactively

Refactoring coordinates for Minecraft Pi buildings written in Python