Skip to content

Commit

Permalink
Merge pull request #92 from scala-exercises/updates-project
Browse files Browse the repository at this point in the history
Updates Project
  • Loading branch information
juanpedromoreno authored Apr 24, 2020
2 parents 1d90206 + be4ac5b commit 34aa7fb
Show file tree
Hide file tree
Showing 21 changed files with 97 additions and 125 deletions.
4 changes: 2 additions & 2 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
version=2.4.2
style = defaultWithAlign
maxColumn = 100

Expand All @@ -19,5 +20,4 @@ docstrings = JavaDoc
rewrite {
rules = [SortImports, RedundantBraces]
redundantBraces.maxLines = 1
}

}
17 changes: 0 additions & 17 deletions .travis.yml

This file was deleted.

1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Scala Exercises - Cats library
------------------------

This repository hosts a content library for the [Scala Exercises](https://www.scala-exercises.org/) platform that includes interactive exercises related to the [Cats library](https://github.com/typelevel/cats) by Typelevel.

Expand Down
37 changes: 13 additions & 24 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,27 +1,16 @@
import ProjectPlugin.autoImport._
val scalaExercisesV = "0.6.0-SNAPSHOT"
addCommandAlias("ci-test", "scalafmtCheckAll; scalafmtSbtCheck; test")
addCommandAlias("ci-docs", "github; project-docs/mdoc; headerCreateAll")

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

lazy val cats = (project in file("."))
lazy val exercises = (project in file("."))
.settings(moduleName := "exercises-cats")
.settings(exercisesSettings)
.enablePlugins(ExerciseCompilerPlugin)
.settings(
name := "exercises-cats",
libraryDependencies ++= Seq(
dep("exercise-compiler"),
dep("definitions"),
%%("cats-core", V.cats),
%%("shapeless", V.shapeless),
%%("scalatest", V.scalatest),
%%("scalacheck", V.scalacheck),
"com.github.alexarchambault" %% "scalacheck-shapeless_1.14" % V.scalacheckShapeless,
"org.scalatestplus" %% "scalatestplus-scalacheck" % V.scalatestplusScheck
),
addCompilerPlugin("org.typelevel" %% "kind-projector" % "0.11.0" cross CrossVersion.full)
)

// Distribution

pgpPassphrase := Some(getEnvVar("PGP_PASSPHRASE").getOrElse("").toCharArray)
pgpPublicRing := file(s"$gpgFolder/pubring.gpg")
pgpSecretRing := file(s"$gpgFolder/secring.gpg")
lazy val `project-docs` = (project in file(".docs"))
.aggregate(exercises)
.dependsOn(exercises)
.settings(moduleName := "exercises-project-docs")
.settings(mdocIn := file(".docs"))
.settings(mdocOut := file("."))
.settings(skip in publish := true)
.enablePlugins(MdocPlugin)
59 changes: 28 additions & 31 deletions project/ProjectPlugin.scala
Original file line number Diff line number Diff line change
@@ -1,55 +1,52 @@
import de.heikoseeberger.sbtheader.HeaderPlugin.autoImport._
import de.heikoseeberger.sbtheader.License._
import sbt.Keys._
import sbt._
import sbtorgpolicies.OrgPoliciesPlugin.autoImport._
import sbtorgpolicies._
import sbtorgpolicies.model._
import com.alejandrohdezma.sbt.github.SbtGithubPlugin

object ProjectPlugin extends AutoPlugin {

override def trigger: PluginTrigger = allRequirements

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

object autoImport {

lazy val V = new {
val scala213: String = "2.13.1"
val cats: String = "2.0.0"
val cats: String = "2.1.1"
val shapeless: String = "2.3.3"
val scalatest: String = "3.1.1"
val scalatestplusScheck: String = "3.1.0.0-RC2"
val scala: String = "2.13.2"
val scalaExercises: String = "0.6.0-SNAPSHOT"
val scalacheck: String = "1.14.3"
val scalacheckShapeless: String = "1.2.5"
val scalatest: String = "3.1.1"
val scalatestplusScheck: String = "3.1.1.1"
}
}

import autoImport._
def dep(artifactId: String) = "org.scala-exercises" %% artifactId % V.scalaExercises

lazy val exercisesSettings = Seq(
libraryDependencies ++= Seq(
dep("exercise-compiler"),
dep("definitions"),
"org.typelevel" %% "cats-core" % V.cats,
"com.chuusai" %% "shapeless" % V.shapeless,
"org.scalatest" %% "scalatest" % V.scalatest,
"org.scalacheck" %% "scalacheck" % V.scalacheck,
"org.scalatestplus" %% "scalacheck-1-14" % V.scalatestplusScheck,
"com.github.alexarchambault" %% "scalacheck-shapeless_1.14" % V.scalacheckShapeless
),
addCompilerPlugin("org.typelevel" %% "kind-projector" % "0.11.0" cross CrossVersion.full)
)
}

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 = "hello@47deg.com"
),
orgLicenseSetting := ApacheLicense,
scalaVersion := V.scala213,
scalaOrganization := "org.scala-lang",
organization := "org.scala-exercises",
organizationName := "47 Degrees",
organizationHomepage := Some(url("https://47deg.com")),
scalaVersion := autoImport.V.scala,
resolvers ++= Seq(
Resolver.mavenLocal,
Resolver.sonatypeRepo("snapshots"),
Resolver.sonatypeRepo("releases")
),
headerLicense := Some(Custom(s"""| scala-exercises - ${name.value}
| Copyright (C) 2015-2020 47 Degrees, LLC. <http://www.47deg.com>
|
|""".stripMargin))
)
)
}
16 changes: 10 additions & 6 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
resolvers ++= Seq(
Resolver.sonatypeRepo("snapshots")
)

addSbtPlugin("org.scala-exercises" % "sbt-exercise" % "0.6.0-SNAPSHOT")
addSbtPlugin("com.47deg" % "sbt-org-policies" % "0.12.0-M3")
resolvers += Resolver.sonatypeRepo("snapshots")
addSbtPlugin("org.scala-exercises" % "sbt-exercise" % "0.6.0-SNAPSHOT")
addSbtPlugin("com.geirsson" % "sbt-ci-release" % "1.5.3")
addSbtPlugin("org.scalameta" % "sbt-mdoc" % "2.1.5")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.3.4")
addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.6.0")
addSbtPlugin("com.alejandrohdezma" %% "sbt-github" % "0.8.0")
addSbtPlugin("com.alejandrohdezma" % "sbt-github-header" % "0.8.0")
addSbtPlugin("com.alejandrohdezma" % "sbt-github-mdoc" % "0.8.0")
addSbtPlugin("com.alejandrohdezma" % "sbt-mdoc-toc" % "0.2")
18 changes: 0 additions & 18 deletions pubring.gpg

This file was deleted.

Binary file removed secring.gpg.enc
Binary file not shown.
3 changes: 2 additions & 1 deletion src/main/scala/catslib/Apply.scala
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ object ApplySection extends AnyFlatSpec with Matchers with org.scalaexercises.de
res1: Option[Int],
res2: Option[Int],
res3: Option[Int],
res4: Option[Int]) = {
res4: Option[Int]
) = {
Apply[Option].ap(Some(intToString))(Some(1)) should be(res0)
Apply[Option].ap(Some(double))(Some(1)) should be(res1)
Apply[Option].ap(Some(double))(None) should be(res2)
Expand Down
3 changes: 2 additions & 1 deletion src/main/scala/catslib/EitherSection.scala
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,8 @@ object EitherSection extends AnyFlatSpec with Matchers with org.scalaexercises.d
def eitherInTheLarge(
res0: Either[String, Int],
res1: Either[String, Int],
res2: Either[String, Int]) = {
res2: Either[String, Int]
) = {
val right: Either[String, Int] = Right(41)
right.map(_ + 1) should be(res0)

Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/catslib/EvalSection.scala
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ object EvalSection extends AnyFlatSpec with Matchers with org.scalaexercises.def
*/
def laterEval(resultList: List[Int], counterResult: Int) = {
//given
val n = 2
val n = 2
var counter = 0
val lazyEval = Eval.later {
println("This is lazyly evaluated with caching")
Expand Down Expand Up @@ -119,7 +119,7 @@ object EvalSection extends AnyFlatSpec with Matchers with org.scalaexercises.def
*/
def alwaysEval(resultList: List[Int], counterAfterListEval: Int, latestCounter: Int) = {
//given
val n = 4
val n = 4
var counter = 0
val alwaysEval = Eval.always {
println("This is lazyly evaluated without caching")
Expand Down
4 changes: 3 additions & 1 deletion src/main/scala/catslib/Foldable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ object FoldableSection
*/
def foldableFold(res0: String, res1: Int) = {
Foldable[List].fold(List("a", "b", "c")) should be(res0)
Foldable[List].fold(List(1, 2, 3)) should be(res1) // Hint: the implicit monoid for `Int` is the Sum monoid
Foldable[List].fold(List(1, 2, 3)) should be(
res1
) // Hint: the implicit monoid for `Int` is the Sum monoid
}

/** = foldMap =
Expand Down
11 changes: 6 additions & 5 deletions src/main/scala/catslib/MonadHelpers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ object MonadHelpers {

def tailRecM[A, B](a: A)(f: A => OptionT[F, Either[A, B]]): OptionT[F, B] =
OptionT(
F.tailRecM(a)(
a0 =>
F.map(f(a0).value)(
_.fold(Either.right[A, Option[B]](None))(_.map(b => Some(b): Option[B]))
)))
F.tailRecM(a)(a0 =>
F.map(f(a0).value)(
_.fold(Either.right[A, Option[B]](None))(_.map(b => Some(b): Option[B]))
)
)
)
}
}
}
3 changes: 2 additions & 1 deletion src/main/scala/catslib/Monoid.scala
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ object MonoidSection extends AnyFlatSpec with Matchers with org.scalaexercises.d
*/
def monoidAdvantage(res0: Map[String, Int], res1: Map[String, Int]) = {
Monoid[Map[String, Int]].combineAll(List(Map("a" -> 1, "b" -> 2), Map("a" -> 3))) should be(
res0)
res0
)
Monoid[Map[String, Int]].combineAll(List()) should be(res1)
}

Expand Down
12 changes: 8 additions & 4 deletions src/main/scala/catslib/OptionTSection.scala
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ object OptionTSection
def fromOptionT(
maybeFrenchGreet: Option[String],
maybeItalianGreet: Option[String],
maybeFailedGreet: Option[String]) = {
maybeFailedGreet: Option[String]
) = {
//given
val frenchGreetFO: Future[Option[String]] = Future.successful(Option("Bonjour"))
val italianGreetF: Future[String] = Future.successful("Ciao")
Expand Down Expand Up @@ -133,7 +134,8 @@ object OptionTSection
maybeGreetH: List[Option[String]],
maybeGreetGuten: List[Option[String]],
maybeGreetGutenTag: List[String],
maybeGreetGutenAbend: List[String]) = {
maybeGreetGutenAbend: List[String]
) = {
//given
val germanGreetingsLO: List[Option[String]] =
List("Hallo".some, "Hi".some, "Guten Morgen".some, none[String])
Expand All @@ -143,11 +145,13 @@ object OptionTSection
//map
germanGreetingsT.map(_ + "!") shouldBe OptionT(maybeGreet: List[Option[String]])
germanGreetingsLO.map(_.map(_ + " World!")) shouldBe OptionT(
maybeGreetWorld: List[Option[String]]).value
maybeGreetWorld: List[Option[String]]
).value
//filter
germanGreetingsT.filter(_.contains("H")) shouldBe OptionT(maybeGreetH: List[Option[String]])
germanGreetingsLO.map(_.filter(_.contains("Guten"))) shouldBe OptionT(
maybeGreetGuten: List[Option[String]]).value
maybeGreetGuten: List[Option[String]]
).value
//getOrElse
germanGreetingsT.getOrElse("Guten Tag") shouldBe (maybeGreetGutenTag: List[String])
germanGreetingsLO.map(_.getOrElse("Guten Abend")) shouldBe (maybeGreetGutenAbend: List[String])
Expand Down
3 changes: 2 additions & 1 deletion src/main/scala/catslib/Semigroup.scala
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ object SemigroupSection
res0: Option[Int],
res1: Option[Int],
res2: Option[Int],
res3: Option[Int]) = {
res3: Option[Int]
) = {
import cats.implicits._

val one: Option[Int] = Option(1)
Expand Down
5 changes: 1 addition & 4 deletions src/main/scala/catslib/Validated.scala
Original file line number Diff line number Diff line change
Expand Up @@ -363,10 +363,7 @@ object ValidatedSection
val config = Config(Map("house_number" -> "-42"))

val houseNumber = config.parse[Int]("house_number").withEither {
either: Either[ConfigError, Int] =>
either.flatMap { i =>
positive("house_number", i)
}
either: Either[ConfigError, Int] => either.flatMap(i => positive("house_number", i))
}

houseNumber.isValid should be(res0)
Expand Down
3 changes: 2 additions & 1 deletion src/main/scala/catslib/ValidatedHelpers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ object ValidatedHelpers {
import cats.Semigroup

def parallelValidate[E: Semigroup, A, B, C](v1: Validated[E, A], v2: Validated[E, B])(
f: (A, B) => C): Validated[E, C] =
f: (A, B) => C
): Validated[E, C] =
(v1, v2) match {
case (Valid(a), Valid(b)) => Valid(f(a, b))
case (Valid(_), i @ Invalid(_)) => i
Expand Down
4 changes: 2 additions & 2 deletions src/test/scala/catslib/EvalSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class EvalSpec extends RefSpec with Checkers {
check(
Test.testSuccess(
EvalSection.nowEval _,
List(1, 2, 3) :: HNil
List(1, 2, 3) :: HNil
)
)
}
Expand Down Expand Up @@ -49,4 +49,4 @@ class EvalSpec extends RefSpec with Checkers {
)
)
}
}
}
14 changes: 12 additions & 2 deletions src/test/scala/catslib/OptionTSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,19 @@ class OptionTSpec extends RefSpec with Checkers {
Test.testSuccess(
OptionTSection.optionTMethods _,
List(Option("Hallo!"), Option("Hi!"), Option("Guten Morgen!"), Option.empty[String]) ::
(List(Option("Hallo World!"), Option("Hi World!"), Option("Guten Morgen World!"), Option.empty[String])) ::
(List(
Option("Hallo World!"),
Option("Hi World!"),
Option("Guten Morgen World!"),
Option.empty[String]
)) ::
List(Option("Hallo"), Option("Hi"), Option.empty[String], Option.empty[String]) ::
List(Option.empty[String], Option.empty[String], Option("Guten Morgen"), Option.empty[String]) ::
List(
Option.empty[String],
Option.empty[String],
Option("Guten Morgen"),
Option.empty[String]
) ::
List("Hallo", "Hi", "Guten Morgen", "Guten Tag") ::
List("Hallo", "Hi", "Guten Morgen", "Guten Abend") :: HNil
)
Expand Down
1 change: 0 additions & 1 deletion version.sbt

This file was deleted.

0 comments on commit 34aa7fb

Please sign in to comment.