Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the scala percent operator (%) and at method for strings do?

Tags:

scala

sbt

val scalaToolsSnapshots = "Scala-Tools Maven2 Snapshots Repository" at "http://scala-tools.org/repo-snapshots"
val specs = "org.scala-tools.testing" % "specs_2.9.0-1" % "1.6.8" % "test"

What does this mean?

like image 302
MetaChrome Avatar asked Nov 24 '11 14:11

MetaChrome


People also ask

What is string * in Scala?

Scala string is an immutable object that means the object cannot be modified. Each element of a string is associated with an index number. The first character is associated with the number 0, the second with the number 1, etc. Class java.

How do you write a string in Scala?

Creating a Stringvar greeting = "Hello world!"; or var greeting:String = "Hello world!"; Whenever compiler encounters a string literal in the code, it creates a String object with its value, in this case, “Hello world!”.

How do you find the length of a string in Scala?

Get length of the string So, a length() method is the accessor method in Scala, which is used to find the length of the given string. Or in other words, length() method returns the number of characters that are present in the string object. Syntax: var len1 = str1.


2 Answers

That is sbt (simple build tool) DSL that defines managed dependencies of project.

Format is quite simular to maven: first line says where to find repository, second line defines dependency like "groupId" % "artifactId" % "version" % "scope"

For details look at the sbt wiki page (section Managed Dependencies)

like image 163
om-nom-nom Avatar answered Nov 15 '22 18:11

om-nom-nom


you can also simplify this declaration using the following :

scalaVersion := "2.9.0-1"

scalaToolsSnapshots := "Scala-Tools Maven2 Snapshots Repository" at "http://scala-tools.org/repo-snapshots"

specs := "org.scala-tools.testing" %% "specs" % "1.6.8" % "test"

%% will specify to sbt to use a specs version that is binary compatible with your project scala version.

You should consider using it especially if you plan to upgrade scala version or if you plan to publish a lib against multiple scala versions.

under the hood, first String is implicitly converted to a GroupID with %% method that convert next String to a GroupArtifactId, the following % creates a ModuleID and the last % adds a scope to the ModuleID.

like image 26
David Avatar answered Nov 15 '22 17:11

David