/scala-samples

There are pieces of scala code that explain Scala syntax and features

Primary LanguageScala

scala-samples

Preface

Sometimes we need read some articles, forums, blogs to understand Scala features. But if we want just remind ourselves something we already knew, then is better just look at code sample. You could easily change it and play with it and see what's going on.

There are samples of Scala code that explains how to use some scala features.

This code is supposed to be isolated as much as possible - like if we wish to explain/remember one feature of Scala then we are not going to use 5 more extra features for that (which might not be gotten yet by a reader of this code).

Each example has no more than 100 lines of code. Also there is tagging is used in order to show to the reader what feature is involved for particular example. Like #feature-1 #feature-3.

"Use the course, Luke!" (R)

HOW TO INSTALL

This is SBT project. So you may follow general rules about how to open it in your ide or console.

For example To convert project to IntellijIdea:

BEFORE: make sure than in your IDE, here "File->Setting->Plugins->Browse repositories":

  1. "Scala v.0.22.302" (> 83 000 downloads) plugin installed
  2. "SBT v. 1.5.1" (>10 000 downloads)" plugin installed

Those versions that I have right now (4 November 2013)

  1. If you use sbt v 0.13 then make sure you have this directory (in your home directory): '~/.sbt/0.13/plugins'
  2. in that file '~/.sbt/0.13/plugins/build.sbt' make sure you have content like this:
    addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.5.2")
  3. For more info: <a href="https://github.com/mpeltonen/sbt-idea">sbt-idea plugin</a>
    

Then usual steps are:

  1. cd ~/[your-path]/scala-samples
  2. sbt
  3. gen-idea
  4. Open project in IDE - just open it as usual IntelliJ idea project

How to launch

Then let's say you want run some file from this project using SBT support.

An an example,

  1. CTRL+N in IDE, type: "ClassWithApplyMethod", go in this file
  2. CTL+G, type "17" (go to line number #17), CTRL+SHIFT+F10 (launch the file project, from that line)
  • you will see that is starts compiling.. (actually for now with no SBT support. ( That's a lame.. I know [this is because of sbt-issue that not fixed yet - see below] )
  • . You may stop it before it's finished (hurry up)! Just click red cross on the bottom panel to make it happen.
  1. In the top toolbar panel, just under menu-panel "Run" & "Tools" you will be able to see "Starter":
  • click on it and go to "Edit Configuration" window
  • There is "Before launch" section:
    • delete "make" from there
    • then click on "+" and add select SBT and select "compile" option
    • click OK to close the "Edit Configuration" window
  1. Now click "Starter" again in the toolbar panel. Now every time when you click on press CTRL+SHIFT+F10, it starts using SBT to compile and launch this particular file / class.. well Object. (firs time it's going to take some time. But next time - it will compile and launch it much faster)

Known SBT-issue for now (found by me. Please vote for them - to make them fixed even faster!)

  1. http://youtrack.jetbrains.com/issue/SCL-6208 (IntelliJ Idea compiling with SBT by default)
  2. http://youtrack.jetbrains.com/issue/SCL-6220 (SBT plugin does not get last changes in the code - this happens only if we don't use any sbt-related files in the project, like build.sbt)

-- Spec: http://www.scala-lang.org/files/archive/spec/2.11/