Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
style = defaultWithAlign
maxColumn = 100

continuationIndent.callSite = 2

newlines {
sometimesBeforeColonInMethodReturnType = false
}

align {
arrowEnumeratorGenerator = false
ifWhileOpenParen = false
openParenCallSite = false
openParenDefnSite = false
}

docstrings = JavaDoc

rewrite {
rules = [SortImports, RedundantBraces]
redundantBraces.maxLines = 1
}

7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#Scala Exercises - Functional Programming Principles library

# Scala Exercises - Functional Programming Principles library
------------------------

This repository hosts a library for the first course of the [Scala MOOC](https://www.coursera.org/specializations/scala) ("Functional Programming Principles in Scala").
Expand Down Expand Up @@ -43,7 +42,7 @@ evaluator.secretKey="secretKey"
sbt -mem 1500 run
~~~

## About Scala exercises
## About Scala exercises

"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.

Expand All @@ -54,7 +53,7 @@ Scala Exercises is available at [scala-exercises.org](https://scala-exercises.or
Contributions welcome! Please join our [Gitter channel](https://gitter.im/scala-exercises/scala-exercises)
to get involved, or visit our [GitHub site](https://github.com/scala-exercises).

##License
## License

Copyright (C) 2015-2016 47 Degrees, LLC.
Reactive, scalable software solutions.
Expand Down
61 changes: 17 additions & 44 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,49 +1,22 @@
val scalaExerciesV = "0.4.0-SNAPSHOT"

def dep(artifactId: String) = "org.scala-exercises" %% artifactId % scalaExerciesV

lazy val `scala-tutorial` = (project in file("."))
.enablePlugins(ExerciseCompilerPlugin)
.settings(publishSettings:_*)
.settings(
organization := "org.scala-exercises",
name := "exercises-scalatutorial",
scalaVersion := "2.11.8",
version := "0.3.0-SNAPSHOT",
resolvers ++= Seq(
Resolver.sonatypeRepo("snapshots"),
Resolver.sonatypeRepo("releases")
),
libraryDependencies ++= Seq(
"org.scalatest" %% "scalatest" % "2.2.4",
"org.scala-exercises" %% "exercise-compiler" % "0.3.0-SNAPSHOT",
"org.scala-exercises" %% "definitions" % "0.3.0-SNAPSHOT",
"org.scalacheck" %% "scalacheck" % "1.12.5",
"com.github.alexarchambault" %% "scalacheck-shapeless_1.12" % "0.3.1",
compilerPlugin("org.spire-math" %% "kind-projector" % "0.7.1")
)
.enablePlugins(ExerciseCompilerPlugin)
.settings(
name := "exercises-scalatutorial",
libraryDependencies ++= Seq(
dep("exercise-compiler"),
dep("definitions"),
%%("scalatest"),
%%("scalacheck"),
%%("scheckShapeless")
)
)

// Distribution

lazy val gpgFolder = sys.env.getOrElse("PGP_FOLDER", ".")

lazy val publishSettings = Seq(
organizationName := "Scala Exercises",
organizationHomepage := Some(new URL("http://scala-exercises.org")),
startYear := Some(2016),
description := "Scala Exercises: The path to enlightenment",
homepage := Some(url("http://scala-exercises.org")),
pgpPassphrase := Some(sys.env.getOrElse("PGP_PASSPHRASE", "").toCharArray),
pgpPublicRing := file(s"$gpgFolder/pubring.gpg"),
pgpSecretRing := file(s"$gpgFolder/secring.gpg"),
credentials += Credentials("Sonatype Nexus Repository Manager", "oss.sonatype.org", sys.env.getOrElse("PUBLISH_USERNAME", ""), sys.env.getOrElse("PUBLISH_PASSWORD", "")),
scmInfo := Some(ScmInfo(url("https://github.com/scala-exercises/exercises-scalatutorial"), "https://github.com/scala-exercises/exercises-scalatutorial.git")),
licenses := Seq("Apache License, Version 2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0.txt")),
publishMavenStyle := true,
publishArtifact in Test := false,
pomIncludeRepository := Function.const(false),
publishTo := {
val nexus = "https://oss.sonatype.org/"
if (isSnapshot.value)
Some("Snapshots" at nexus + "content/repositories/snapshots")
else
Some("Releases" at nexus + "service/local/staging/deploy/maven2")
}
)
pgpPassphrase := Some(getEnvVar("PGP_PASSPHRASE").getOrElse("").toCharArray)
pgpPublicRing := file(s"$gpgFolder/pubring.gpg")
pgpSecretRing := file(s"$gpgFolder/secring.gpg")
47 changes: 47 additions & 0 deletions project/ProjectPlugin.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import de.heikoseeberger.sbtheader.HeaderPattern
import de.heikoseeberger.sbtheader.HeaderPlugin.autoImport._
import sbt.Keys._
import sbt._
import sbtorgpolicies._
import sbtorgpolicies.model._
import sbtorgpolicies.OrgPoliciesPlugin.autoImport._

object ProjectPlugin extends AutoPlugin {

override def trigger: PluginTrigger = allRequirements

override def requires: Plugins = plugins.JvmPlugin && OrgPoliciesPlugin

override def projectSettings: Seq[Def.Setting[_]] =
Seq(
description := "Scala Exercises: The path to enlightenment",
startYear := Option(2016),
orgGithubSetting := GitHubSettings(
organization = "scala-exercises",
project = name.value,
organizationName = "Scala Exercises",
groupId = "org.scala-exercises",
organizationHomePage = url("https://www.scala-exercises.org"),
organizationEmail = "[email protected]"
),
orgLicenseSetting := ApacheLicense,
scalaVersion := "2.11.8",
scalaOrganization := "org.scala-lang",
crossScalaVersions := Seq("2.11.8"),
resolvers ++= Seq(
Resolver.mavenLocal,
Resolver.sonatypeRepo("snapshots"),
Resolver.sonatypeRepo("releases")
),
scalacOptions := sbtorgpolicies.model.scalacCommonOptions,
headers := Map(
"scala" -> (HeaderPattern.cStyleBlockComment,
s"""|/*
| * scala-exercises - ${name.value}
| * Copyright (C) 2015-2016 47 Degrees, LLC. <http://www.47deg.com>
| */
|
|""".stripMargin)
)
)
}
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version = 0.13.8
sbt.version=0.13.13
9 changes: 6 additions & 3 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
resolvers += Resolver.sonatypeRepo("snapshots")
addSbtPlugin("org.scala-exercises" % "sbt-exercise" % "0.3.0-SNAPSHOT", "0.13", "2.10")
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.0.0")
resolvers ++= Seq(
Resolver.sonatypeRepo("snapshots")
)

addSbtPlugin("org.scala-exercises" % "sbt-exercise" % "0.4.0-SNAPSHOT", "0.13", "2.10")
addSbtPlugin("com.47deg" % "sbt-org-policies" % "0.3.2")
17 changes: 11 additions & 6 deletions src/main/scala/scalatutorial/ScalaTutorial.scala
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
/*
* scala-exercises - exercises-scalatutorial
* Copyright (C) 2015-2016 47 Degrees, LLC. <http://www.47deg.com>
*/

package scalatutorial

import org.scalaexercises.definitions.Library

import sections._

/** Quickly learn Scala through an interactive tutorial based on the first two courses of the Scala MOOCs.
*
* @param name scala_tutorial
*/
*
* @param name scala_tutorial
*/
object ScalaTutorial extends Library {
val owner = "scala-exercises"
val repository = "exercises-scalatutorial"
val owner = "scala-exercises"
val repository = "exercises-scalatutorial"
override val color = Some("#f26527")
val logoPath = "scala-tutorial"
val logoPath = "scala-tutorial"

val sections = List(
TermsAndTypes,
Expand Down
14 changes: 9 additions & 5 deletions src/main/scala/scalatutorial/aux/BankAccount.scala
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
/*
* scala-exercises - exercises-scalatutorial
* Copyright (C) 2015-2016 47 Degrees, LLC. <http://www.47deg.com>
*/

package scalatutorial.aux

class BankAccount {

private var balance = 0

def deposit(amount: Int): Unit = {
def deposit(amount: Int): Unit =
if (amount > 0) balance = balance + amount
}

def withdraw(amount: Int): Int =
if (0 < amount && amount <= balance) {
balance = balance - amount
balance
balance = balance - amount
balance
} else throw new Error("insufficient funds")
}
}
11 changes: 8 additions & 3 deletions src/main/scala/scalatutorial/aux/IntSet.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/*
* scala-exercises - exercises-scalatutorial
* Copyright (C) 2015-2016 47 Degrees, LLC. <http://www.47deg.com>
*/

package scalatutorial.aux

abstract class IntSet {
Expand All @@ -7,17 +12,17 @@ abstract class IntSet {

object Empty extends IntSet {
def contains(x: Int): Boolean = false
def incl(x: Int): IntSet = new NonEmpty(x, Empty, Empty)
def incl(x: Int): IntSet = new NonEmpty(x, Empty, Empty)
}
class NonEmpty(elem: Int, left: IntSet, right: IntSet) extends IntSet {

def contains(x: Int): Boolean =
if (x < elem) left contains x
else if (x > elem) right contains x
else if (x > elem) right contains x
else true

def incl(x: Int): IntSet =
if (x < elem) new NonEmpty(elem, left incl x, right)
else if (x > elem) new NonEmpty(elem, left, right incl x)
else this
}
}
5 changes: 5 additions & 0 deletions src/main/scala/scalatutorial/aux/Note.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/*
* scala-exercises - exercises-scalatutorial
* Copyright (C) 2015-2016 47 Degrees, LLC. <http://www.47deg.com>
*/

package scalatutorial.aux

case class Note(name: String, duration: String, octave: Int)
7 changes: 6 additions & 1 deletion src/main/scala/scalatutorial/aux/Rational.scala
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
/*
* scala-exercises - exercises-scalatutorial
* Copyright (C) 2015-2016 47 Degrees, LLC. <http://www.47deg.com>
*/

package scalatutorial.aux

class Rational(x: Int, y: Int) {

private def gcd(a: Int, b: Int): Int = if (b == 0) a else gcd(b, a % b)
private val g = gcd(x, y)
private val g = gcd(x, y)

lazy val numer: Int = x / g
lazy val denom: Int = y / g
Expand Down
5 changes: 5 additions & 0 deletions src/main/scala/scalatutorial/aux/animals.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/*
* scala-exercises - exercises-scalatutorial
* Copyright (C) 2015-2016 47 Degrees, LLC. <http://www.47deg.com>
*/

package scalatutorial.aux

trait Animal {
Expand Down
9 changes: 7 additions & 2 deletions src/main/scala/scalatutorial/aux/sorting.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/*
* scala-exercises - exercises-scalatutorial
* Copyright (C) 2015-2016 47 Degrees, LLC. <http://www.47deg.com>
*/

package scalatutorial.aux

object Sorting {
Expand All @@ -12,9 +17,9 @@ object Sorting {
}

xs match {
case List() => List()
case List() => List()
case y :: ys => insert(y, insertionSort(ys))
}
}

}
}
Loading