Skip to content
Permalink
Browse files

Updated to Scala 2.13.1

  • Loading branch information
kiroco12 committed Jan 24, 2020
1 parent 34b99ca commit 7fed1de3dc6b74b35f0a4696599a4e7f94746b40
@@ -1,5 +1,5 @@
import ProjectPlugin.autoImport._
val scalaExercisesV = "0.5.0-SNAPSHOT"
val scalaExercisesV = "0.6.0-SNAPSHOT"

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

@@ -15,7 +15,7 @@ object ProjectPlugin extends AutoPlugin {
object autoImport {

lazy val V = new {
val scala212: String = "2.12.10"
val scala213: String = "2.13.1"
val cats: String = "2.0.0"
val shapeless: String = "2.3.3"
val scalatest: String = "3.1.0"
@@ -40,14 +40,13 @@ object ProjectPlugin extends AutoPlugin {
organizationEmail = "hello@47deg.com"
),
orgLicenseSetting := ApacheLicense,
scalaVersion := V.scala212,
scalaVersion := V.scala213,
scalaOrganization := "org.scala-lang",
resolvers ++= Seq(
Resolver.mavenLocal,
Resolver.sonatypeRepo("snapshots"),
Resolver.sonatypeRepo("releases")
),
scalacOptions += "-Ypartial-unification",
headerLicense := Some(Custom(s"""| scala-exercises - ${name.value}
| Copyright (C) 2015-2019 47 Degrees, LLC. <http://www.47deg.com>
|
@@ -1 +1 @@
sbt.version=1.2.8
sbt.version=1.3.7
@@ -2,5 +2,5 @@ resolvers ++= Seq(
Resolver.sonatypeRepo("snapshots")
)

addSbtPlugin("org.scala-exercises" % "sbt-exercise" % "0.5.0-SNAPSHOT")
addSbtPlugin("org.scala-exercises" % "sbt-exercise" % "0.6.0-SNAPSHOT")
addSbtPlugin("com.47deg" % "sbt-org-policies" % "0.12.0-M3")
@@ -56,9 +56,9 @@ object ApplySection extends AnyFlatSpec with Matchers with org.scalaexercises.de
def applyExtendsFunctor(res0: Option[String], res1: Option[Int], res2: Option[Int]) = {
import cats.implicits._

val intToString: Int String = _.toString
val double: Int Int = _ * 2
val addTwo: Int Int = _ + 2
val intToString: Int => String = _.toString
val double: Int => Int = _ * 2
val addTwo: Int => Int = _ + 2

Apply[Option].map(Some(1))(intToString) should be(res0)
Apply[Option].map(Some(1))(double) should be(res1)
@@ -71,7 +71,7 @@ object ApplySection extends AnyFlatSpec with Matchers with org.scalaexercises.de
*/
def applyComposes(res0: List[Option[Int]]) = {
val listOpt = Apply[List] compose Apply[Option]
val plusOne = (x: Int) x + 1
val plusOne = (x: Int) => x + 1
listOpt.ap(List(Some(plusOne)))(List(Some(1), None, Some(3))) should be(res0)
}

@@ -102,11 +102,11 @@ object ApplySection extends AnyFlatSpec with Matchers with org.scalaexercises.de
* are carried through the entire computation:
*/
def applyApn(res0: Option[Int], res1: Option[Int], res2: Option[Int]) = {
val addArity2 = (a: Int, b: Int) a + b
val addArity2 = (a: Int, b: Int) => a + b
Apply[Option].ap2(Some(addArity2))(Some(1), Some(2)) should be(res0)
Apply[Option].ap2(Some(addArity2))(Some(1), None) should be(res1)

val addArity3 = (a: Int, b: Int, c: Int) a + b + c
val addArity3 = (a: Int, b: Int, c: Int) => a + b + c
Apply[Option].ap3(Some(addArity3))(Some(1), Some(2), Some(3)) should be(res2)
}

@@ -7,9 +7,9 @@
package catslib

object ApplyHelpers {
val intToString: Int String = _.toString
val double: Int Int = _ * 2
val addTwo: Int Int = _ + 2
val addArity2 = (a: Int, b: Int) a + b
val addArity3 = (a: Int, b: Int, c: Int) a + b + c
val intToString: Int => String = _.toString
val double: Int => Int = _ * 2
val addTwo: Int => Int = _ + 2
val addArity2 = (a: Int, b: Int) => a + b
val addArity3 = (a: Int, b: Int, c: Int) => a + b + c
}
@@ -118,10 +118,10 @@ object EitherSection extends AnyFlatSpec with Matchers with org.scalaexercises.d
def eitherMonad(res0: Either[String, Int], res1: Either[String, Int]) = {

val right: Either[String, Int] = Either.right(5)
right.flatMap(x Either.right(x + 1)) should be(res0)
right.flatMap(x => Either.right(x + 1)) should be(res0)

val left: Either[String, Int] = Either.left("Something went wrong")
left.flatMap(x Either.right(x + 1)) should be(res1)
left.flatMap(x => Either.right(x + 1)) should be(res1)
}

/** = Using `Either` instead of exceptions =
@@ -201,10 +201,10 @@ object EitherSection extends AnyFlatSpec with Matchers with org.scalaexercises.d
import EitherStyle._

val result = magic("2") match {
case Left(_: NumberFormatException) "Not a number!"
case Left(_: IllegalArgumentException) "Can't take reciprocal of 0!"
case Left(_) "Unknown error"
case Right(result) s"Got reciprocal: ${result}"
case Left(_: NumberFormatException) => "Not a number!"
case Left(_: IllegalArgumentException) => "Can't take reciprocal of 0!"
case Left(_) => "Unknown error"
case Right(result) => s"Got reciprocal: ${result}"
}
result should be(res0)
}
@@ -243,9 +243,9 @@ object EitherSection extends AnyFlatSpec with Matchers with org.scalaexercises.d
import EitherStyleWithAdts._

val result = magic("2") match {
case Left(NotANumber(_)) "Not a number!"
case Left(NoZeroReciprocal) "Can't take reciprocal of 0!"
case Right(result) s"Got reciprocal: ${result}"
case Left(NotANumber(_)) => "Not a number!"
case Left(NoZeroReciprocal) => "Can't take reciprocal of 0!"
case Right(result) => s"Got reciprocal: ${result}"
}
result should be(res0)
}
@@ -64,7 +64,7 @@ object FoldableSection
*/
def foldableFoldRight(res0: Int) = {
val lazyResult =
Foldable[List].foldRight(List(1, 2, 3), Now(0))((x, rest) Later(x + rest.value))
Foldable[List].foldRight(List(1, 2, 3), Now(0))((x, rest) => Later(x + rest.value))
lazyResult.value should be(res0)
}

@@ -112,7 +112,7 @@ object FunctorSection
*
*/
def liftingToAFunctor(res0: Option[Int]) = {
val lenOption: Option[String] Option[Int] = Functor[Option].lift(_.length)
val lenOption: Option[String] => Option[Int] = Functor[Option].lift(_.length)
lenOption(Some("Hello")) should be(res0)
}

@@ -85,7 +85,7 @@ object MonadSection extends AnyFlatSpec with Matchers with org.scalaexercises.de
import cats._
import cats.implicits._

Monad[List].flatMap(List(1, 2, 3))(x List(x, x)) should be(res0)
Monad[List].flatMap(List(1, 2, 3))(x => List(x, x)) should be(res0)
}

/** = ifM =
@@ -15,11 +15,11 @@ object MonadHelpers {
implicit def optionTMonad[F[_]](implicit F: Monad[F]) = {
new Monad[OptionT[F, *]] {
def pure[A](a: A): OptionT[F, A] = OptionT(F.pure(Some(a)))
def flatMap[A, B](fa: OptionT[F, A])(f: A OptionT[F, B]): OptionT[F, B] =
def flatMap[A, B](fa: OptionT[F, A])(f: A => OptionT[F, B]): OptionT[F, B] =
OptionT {
F.flatMap(fa.value) {
case None F.pure(None)
case Some(a) f(a).value
case None => F.pure(None)
case Some(a) => f(a).value
}
}

@@ -55,7 +55,8 @@ object MonoidSection extends AnyFlatSpec with Matchers with org.scalaexercises.d
* operate on more complex types, e.g.
*/
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)
Monoid[Map[String, Int]].combineAll(List(Map("a" -> 1, "b" -> 2), Map("a" -> 3))) should be(
res0)
Monoid[Map[String, Int]].combineAll(List()) should be(res1)
}

@@ -67,7 +68,7 @@ object MonoidSection extends AnyFlatSpec with Matchers with org.scalaexercises.d
def monoidFoldmap(res0: Int, res1: String) = {
val l = List(1, 2, 3, 4, 5)
l.foldMap(identity) should be(res0)
l.foldMap(i i.toString) should be(res1)
l.foldMap(i => i.toString) should be(res1)
}

/** To use this
@@ -91,6 +92,6 @@ object MonoidSection extends AnyFlatSpec with Matchers with org.scalaexercises.d
*/
def tupleMonoid(res0: (Int, String)) = {
val l = List(1, 2, 3, 4, 5)
l.foldMap(i (i, i.toString)) should be(res0)
l.foldMap(i => (i, i.toString)) should be(res0)
}
}
@@ -87,8 +87,8 @@ object SemigroupSection
def composingSemigroups(res0: Map[String, Int]) = {
import cats.implicits._

val aMap = Map("foo" Map("bar" 5))
val anotherMap = Map("foo" Map("bar" 6))
val aMap = Map("foo" -> Map("bar" -> 5))
val anotherMap = Map("foo" -> Map("bar" -> 6))
val combinedMap = Semigroup[Map[String, Map[String, Int]]].combine(aMap, anotherMap)

combinedMap.get("foo") should be(Some(res0))
@@ -331,9 +331,9 @@ object ValidatedSection
* }}}
*/
def sequentialValidation(res0: Boolean, res1: Boolean) = {
val config = Config(Map("house_number" "-42"))
val config = Config(Map("house_number" -> "-42"))

val houseNumber = config.parse[Int]("house_number").andThen { n
val houseNumber = config.parse[Int]("house_number").andThen { n =>
if (n >= 0) Validated.valid(n)
else Validated.invalid(ParseError("house_number"))
}
@@ -360,11 +360,11 @@ object ValidatedSection
*
*/
def validatedAsEither(res0: Boolean, res1: Boolean) = {
val config = Config(Map("house_number" "-42"))
val config = Config(Map("house_number" -> "-42"))

val houseNumber = config.parse[Int]("house_number").withEither {
either: Either[ConfigError, Int]
either.flatMap { i
either: Either[ConfigError, Int] =>
either.flatMap { i =>
positive("house_number", i)
}
}
@@ -37,24 +37,24 @@ object ValidatedHelpers {
case class Config(map: Map[String, String]) {
def parse[A: Read](key: String): Validated[ConfigError, A] =
map.get(key) match {
case None Invalid(MissingConfig(key))
case Some(value)
case None => Invalid(MissingConfig(key))
case Some(value) =>
Read[A].read(value) match {
case None Invalid(ParseError(key))
case Some(a) Valid(a)
case None => Invalid(ParseError(key))
case Some(a) => Valid(a)
}
}
}

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
case (i @ Invalid(_), Valid(_)) i
case (Invalid(e1), Invalid(e2)) Invalid(Semigroup[E].combine(e1, e2))
case (Valid(a), Valid(b)) => Valid(f(a, b))
case (Valid(_), i @ Invalid(_)) => i
case (i @ Invalid(_), Valid(_)) => i
case (Invalid(e1), Invalid(e2)) => Invalid(Semigroup[E].combine(e1, e2))
}

import cats.SemigroupK
@@ -23,7 +23,7 @@ class MonoidSpec extends RefSpec with Checkers {
}

def `advantages of using monoid operations` = {
val aMap: Map[String, Int] = Map("a" 4, "b" 2)
val aMap: Map[String, Int] = Map("a" -> 4, "b" -> 2)
val anotherMap: Map[String, Int] = Map()

check(
@@ -35,7 +35,7 @@ class SemigroupSpec extends RefSpec with Checkers {
check(
Test.testSuccess(
SemigroupSection.composingSemigroups _,
Map("bar" 11) :: HNil
Map("bar" -> 11) :: HNil
)
)
}
@@ -1 +1 @@
version in ThisBuild := "0.5.0-SNAPSHOT"
version in ThisBuild := "0.6.0-SNAPSHOT"

0 comments on commit 7fed1de

Please sign in to comment.
You can’t perform that action at this time.