Skip to content

Commit 997e5a1

Browse files
Merge pull request #1 from scalacenter/master
Add a Scala tutorial
2 parents f81a5d7 + 8421898 commit 997e5a1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+4622
-67
lines changed

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,45 @@
44

55
This repository hosts a library for the first course of the [Scala MOOC](https://www.coursera.org/specializations/scala) ("Functional Programming Principles in Scala").
66

7+
## Run Locally
8+
9+
- Clone this repository, compile and publish the project:
10+
11+
~~~ sh
12+
git clone git@github.com:scala-exercises/exercises-scalatutorial.git
13+
cd exercises-scalatutorial/
14+
sbt compile publishLocal # it is important to first run the `compile` command alone
15+
~~~
16+
17+
- Clone the `evaluator` and run it:
18+
19+
~~~ sh
20+
git clone git@github.com:scala-exercises/evaluator.git
21+
cd evaluator/
22+
sbt "project evaluator-server" run
23+
~~~
24+
25+
- Clone the `scala-tutorial` branch of our `scala-exercises` fork:
26+
27+
~~~ sh
28+
git clone -b scala-tutorial git@github.com:scalacenter/scala-exercises.git
29+
~~~
30+
31+
- Follow the database setup instructions given
32+
[here](https://github.com/scala-exercises/scala-exercises#configure-the-database)
33+
34+
- Add the following line the `server/conf/application.dev.conf`:
35+
36+
~~~
37+
evaluator.secretKey="secretKey"
38+
~~~
39+
40+
- Run the server:
41+
42+
~~~ sh
43+
sbt -mem 1500 run
44+
~~~
45+
746
## About Scala exercises
847

948
"Scala Exercises" brings exercises for the Stdlib, Cats, Shapeless and many other great libraries for Scala to your browser. Offering hundreds of solvable exercises organized into several categories covering the basics of the Scala language and it's most important libraries.

build.sbt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
lazy val template = (project in file("."))
1+
lazy val `scala-tutorial` = (project in file("."))
22
.enablePlugins(ExerciseCompilerPlugin)
33
.settings(
44
organization := "org.scala-exercises",
5-
name := "exercises-fpprinciples",
5+
name := "exercises-scalatutorial",
66
scalaVersion := "2.11.8",
7-
version := "0.3.1-SNAPSHOT",
7+
version := "0.3.0-SNAPSHOT",
88
resolvers ++= Seq(
99
Resolver.sonatypeRepo("snapshots"),
1010
Resolver.sonatypeRepo("releases")

src/main/resources/public/scala_tutorial/animals.svg

Lines changed: 4 additions & 0 deletions
Loading
12.2 KB
Loading
119 KB
Loading

src/main/resources/scala-tutorial.svg

Lines changed: 23 additions & 0 deletions
Loading

src/main/scala/fpprincipleslib/FpPrinciplesLibrary.scala

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/main/scala/fpprincipleslib/FunctionsAndEvaluationSection.scala

Lines changed: 0 additions & 30 deletions
This file was deleted.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package scalatutorial
2+
3+
import org.scalaexercises.definitions.Library
4+
5+
import sections._
6+
7+
/** Quickly learn Scala through an interactive tutorial.
8+
*
9+
* @param name scala_tutorial
10+
*/
11+
object ScalaTutorial extends Library {
12+
val owner = "scala-exercises"
13+
val repository = "exercises-scalatutorial"
14+
override val color = Some("#f26527")
15+
val logoPath = "scala-tutorial"
16+
17+
val sections = List(
18+
TermsAndTypes,
19+
DefinitionsAndEvaluation,
20+
FunctionalLoops,
21+
LexicalScopes,
22+
TailRecursion,
23+
StructuringInformation,
24+
HigherOrderFunctions,
25+
StandardLibrary,
26+
SyntacticConveniences,
27+
ObjectOrientedProgramming,
28+
ImperativeProgramming,
29+
ClassesVsCaseClasses,
30+
PolymorphicTypes,
31+
LazyEvaluation,
32+
TypeClasses
33+
)
34+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package scalatutorial.aux
2+
3+
class BankAccount {
4+
5+
private var balance = 0
6+
7+
def deposit(amount: Int): Unit = {
8+
if (amount > 0) balance = balance + amount
9+
}
10+
11+
def withdraw(amount: Int): Int =
12+
if (0 < amount && amount <= balance) {
13+
balance = balance - amount
14+
balance
15+
} else throw new Error("insufficient funds")
16+
}

0 commit comments

Comments
 (0)