Skip to content
Permalink
Browse files

Update to Scala 2.12.10

  • Loading branch information
kiroco12 committed Nov 29, 2019
1 parent 2f87748 commit 41f96a262530d54900de51d2b18062cd9f60967d
@@ -1,8 +1,8 @@
language: scala
scala:
- 2.11.11
- 2.12.110
jdk:
- oraclejdk8
- openjdk8
script:
- sbt test

@@ -1,21 +1,25 @@
val scalaExercisesV = "0.4.0-SNAPSHOT"
import ProjectPlugin.autoImport._

val scalaExercisesV = "0.5.0-SNAPSHOT"

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

lazy val monocle = (project in file("."))
.enablePlugins(ExerciseCompilerPlugin)
.settings(
name := "exercises-monocle",
libraryDependencies ++= Seq(
dep("exercise-compiler"),
dep("definitions"),
%%("monocle-core" ),
%%("monocle-macro" ),
%%("scalatest"),
%%("scalacheck"),
%%("scheckShapeless")
)
)
.enablePlugins(ExerciseCompilerPlugin)
.settings(
name := "exercises-monocle",
libraryDependencies ++= Seq(
dep("exercise-compiler"),
dep("definitions"),
%%("monocle-core", V.monocle),
%%("monocle-macro", V.monocle),
%%("scalatest", V.scalatest),
%%("scalacheck", V.scalacheck),
"org.typelevel" %% "alleycats-core" % V.cats,
"com.github.alexarchambault" %% "scalacheck-shapeless_1.14" % V.scalacheckShapeless
),
addCompilerPlugin("org.scalamacros" %% "paradise" % "2.1.1" cross CrossVersion.full)
)

// Distribution

@@ -1,4 +1,4 @@
import de.heikoseeberger.sbtheader.HeaderPattern
import de.heikoseeberger.sbtheader.License._
import de.heikoseeberger.sbtheader.HeaderPlugin.autoImport._
import sbt.Keys._
import sbt._
@@ -12,6 +12,21 @@ object ProjectPlugin extends AutoPlugin {

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

object autoImport {

lazy val V = new {
val scala212: String = "2.12.10"
val cats: String = "2.0.0"
val monocle: String = "2.0.0"
val shapeless: String = "2.3.3"
val scalatest: String = "3.0.8"
val scalacheck: String = "1.14.2"
val scalacheckShapeless: String = "1.2.3"
}
}

import autoImport._

override def projectSettings: Seq[Def.Setting[_]] =
Seq(
description := "Scala Exercises: The path to enlightenment",
@@ -25,23 +40,17 @@ object ProjectPlugin extends AutoPlugin {
organizationEmail = "hello@47deg.com"
),
orgLicenseSetting := ApacheLicense,
scalaVersion := "2.11.11",
scalaVersion := V.scala212,
scalaOrganization := "org.scala-lang",
crossScalaVersions := Seq("2.11.11"),
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)
)
scalacOptions := scalacCommonOptions ++ scalacLanguageOptions ++ Seq("-Ypartial-unification"),
headerLicense := Some(Custom(s"""| scala-exercises - ${name.value}
| Copyright (C) 2015-2019 47 Degrees, LLC. <http://www.47deg.com>
|
|""".stripMargin))
)
}
@@ -1 +1 @@
sbt.version = 0.13.13
sbt.version = 1.2.8
@@ -1,3 +1,6 @@
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.5.13")
resolvers ++= Seq(
Resolver.sonatypeRepo("snapshots")
)

addSbtPlugin("org.scala-exercises" % "sbt-exercise" % "0.5.0-SNAPSHOT")
addSbtPlugin("com.47deg" % "sbt-org-policies" % "0.12.0-M3")
@@ -1,10 +1,12 @@
/*
* scala-exercises - exercises-monocle
* Copyright (C) 2015-2016 47 Degrees, LLC. <http://www.47deg.com>
* scala-exercises - exercises-monocle
* Copyright (C) 2015-2019 47 Degrees, LLC. <http://www.47deg.com>
*
*/

package monocle
package monoclelib

import monocle.Iso
import monocle.macros.GenIso
import org.scalatest._
import org.scalaexercises.definitions._
@@ -32,7 +34,7 @@ object IsoHelper {
*
* An [[http://julien-truffaut.github.io/Monocle/optics/iso.html `Iso`]] is an optic which converts elements of type `S` into elements of type `A` without loss.
*
* Consider a case class Person with two fields:
* Consider a case class `Person` with two fields:
*
* {{{
* case class Person(name: String, age: Int)
@@ -96,7 +98,9 @@ object IsoExercises extends FlatSpec with Matchers with Section {
stringToList.modify(_.tail)("Hello") should be(res0)

/**
* We defined several macros to simplify the generation of Iso between a case class and its Tuple equivalent. All macros are defined in a separate module (see modules).
* = Iso Generation =
*
* We defined several macros to simplify the generation of `Iso` between a case class and its `Tuple` equivalent. All macros are defined in a separate module (see modules).
* {{{
* case class MyString(s: String)
* case class Foo()
@@ -1,12 +1,14 @@
/*
* scala-exercises - exercises-monocle
* Copyright (C) 2015-2016 47 Degrees, LLC. <http://www.47deg.com>
* scala-exercises - exercises-monocle
* Copyright (C) 2015-2019 47 Degrees, LLC. <http://www.47deg.com>
*
*/

package monocleex
package monoclelib

import monocle.Lens
import monocle.macros.GenLens
import monocle.macros.Lenses
import org.scalaexercises.definitions._
import org.scalatest._

@@ -24,11 +26,20 @@ object LensHelper {

val addressLens = GenLens[Person](_.address)

@Lenses
case class Point(x: Int, y: Int)
val p = Point(5, 3)

@Lenses("_")
case class OtherPoint(x: Int, y: Int)
val op = OtherPoint(5, 3)

}

/** == Lens ==
*
* A [[http://julien-truffaut.github.io/Monocle/optics/lens.html Lens]] is an optic used to zoom inside a `Product`, e.g. `case class`, `Tuple`, `HList` or even `Map`.
*
* `Lenses` have two type parameters generally called `S` and `A`: `Lens[S, A]` where `S` represents the `Product` and `A` an element inside of `S`.
*
* Let’s take a simple case class with two fields:
@@ -81,16 +92,16 @@ object LensExercises extends FlatSpec with Matchers with Section {
}

/**
* We can push the idea even further, with `modifyF` we can update the target of a `Lens` in a context, cf `scalaz.Functor`:
* We can push the idea even further, with `modifyF` we can update the target of a `Lens` in a context, cf `cats.Functor`:
* {{{
* def neighbors(n: Int): List[Int] =
* if(n > 0) List(n - 1, n + 1) else List(n + 1)
*
* import scalaz.std.list._ // to get Functor[List] instance
* import cats.implicits._ // to get Functor[List] instance
* }}}
*/
def exerciseModifyF(res0: List[Address], res1: List[Address]) = {
import scalaz.std.list._ // to get Functor[List] instance
import cats.implicits._ // to get Functor[List] instance
streetNumber.modifyF(neighbors)(address) should be(res0)
streetNumber.modifyF(neighbors)(Address(135, "High Street")) should be(res1)
}
@@ -100,11 +111,10 @@ object LensExercises extends FlatSpec with Matchers with Section {
* This would work with any kind of `Functor` and is especially useful in conjunction with asynchronous APIs, where one has the task to update a deeply nested structure with the result of an asynchronous computation:
*
* {{{
* import scalaz.std.scalaFuture._
* import scala.concurrent._
* import scala.concurrent.ExecutionContext.Implicits._ // to get global ExecutionContext
* import scala.concurrent._
* import scala.concurrent.ExecutionContext.Implicits._ // to get global ExecutionContext
*
* def updateNumber(n: Int): Future[Int] = Future.successful(n + 1)
* def updateNumber(n: Int): Future[Int] = Future.successful(n + 1)
* }}}
* {{{
* strNumber.modifyF(updateNumber)(address)
@@ -126,6 +136,42 @@ object LensExercises extends FlatSpec with Matchers with Section {
(addressLens composeLens streetNumber).set(2)(john) should be(res1)
}

/**
* = Other Ways of Lens Composition =
*
* Is possible to compose few `Lenses` together by using `compose`:
*/
def exerciseComposeMacro(res0: Person) = {
val compose = GenLens[Person](_.name).set("Mike") compose GenLens[Person](_.age).modify(_ + 1)

compose(john) shouldBe res0
}

/**
* Same but with the simplified macro based syntax:
* {{{
* import monocle.macros.syntax.lens._
*
* john.lens(_.name).set("Mike").lens(_.age).modify(_ + 1)
* }}}
*
* (All `Setter` like optics offer `set` and `modify` methods that returns an `EndoFunction` (i.e. `S => S`) which means that we can compose modification using basic function composition.)
*
* Sometimes you need an easy way to update `Product` type inside `Sum` type - for that case you can compose `Prism` with `Lens` by using `some`:
*/
def exerciseLensPrismComposition(res0: Option[Int]) = {
import monocle.std.option.some
import monocle.macros.GenLens

case class B(c: Int)
case class A(b: Option[B])

val c = GenLens[B](_.c)
val b = GenLens[A](_.b)

(b composePrism some composeLens c).getOption(A(Some(B(1)))) shouldBe res0
}

/**
* == Lens Generation ==
*
@@ -140,12 +186,37 @@ object LensExercises extends FlatSpec with Matchers with Section {
def exerciseLensGeneration(res0: Person) =
GenLens[Person](_.address.streetName).set("Iffley Road")(john) should be(res0)

/**
* For those who want to push `Lenses` generation even further, we created `@Lenses` macro annotation which generate `Lenses` for all fields of a case class. The generated `Lenses` are in the companion object of the case class:
*
* {{{
* import monocle.macros.Lenses
*
* @Lenses case class Point(x: Int, y: Int)
* val p = Point(5, 3)
* }}}
*/
def exerciseLensMacroAnn(res0: Int, res1: Point) = {
Point.x.get(p) shouldBe res0
Point.y.set(0)(p) shouldBe res1
}

/**
* You can also add a prefix to `@Lenses` in order to prefix the generated `Lenses`:
* {{{
* @Lenses("_") case class OtherPoint(x: Int, y: Int)
* val op = OtherPoint(5, 3)
* }}}
*/
def exerciseLensMacroAnnPrefix(res0: Int) =
OtherPoint._x.get(op) shouldBe res0

/**
* == Laws ==
*
* A `Lens` must satisfy all properties defined in `LensLaws` from the core module. You can check the validity of your own `Lenses` using `LensTests` from the law module.
* A `Lens` must satisfy all properties defined in `LensLaws` from the `core` module. You can check the validity of your own Lenses` using `LensTests` from the `law` module.
*
* In particular, a Lens must respect the `getSet` law which states that if you get a value `A` from `S` and set it back in, the result is an object identical to the original one. A side effect of this law is that set must only update the `A` it points to, for example it cannot increment a counter or modify another value.
* In particular, a `Lens` must respect the `getSet` law which states that if you get a value `A` from `S` and `set` it back in, the result is an object identical to the original one. A side effect of this law is that `set` must only update the `A` it points to, for example it cannot increment a counter or modify another value.
*
* On the other hand, the `setGet` law states that if you `set` a `value`, you always `get` the same value back. This law guarantees that `set` is actually updating a value `A` inside of `S`.
*
@@ -1,11 +1,11 @@
/*
* scala-exercises - exercises-monocle
* Copyright (C) 2015-2016 47 Degrees, LLC. <http://www.47deg.com>
* scala-exercises - exercises-monocle
* Copyright (C) 2015-2019 47 Degrees, LLC. <http://www.47deg.com>
*
*/

package monocleex
package monoclelib

import monocle.{IsoExercises, OptionalExercises, PrismExercises, TraversalExercises}
import org.scalaexercises.definitions._

/** Monocle is an optics library for Scala (and Scala.js) strongly inspired by Haskell Lens.
@@ -1,11 +1,12 @@
/*
* scala-exercises - exercises-monocle
* Copyright (C) 2015-2016 47 Degrees, LLC. <http://www.47deg.com>
* scala-exercises - exercises-monocle
* Copyright (C) 2015-2019 47 Degrees, LLC. <http://www.47deg.com>
*
*/

package monocle
package monoclelib

import monocle.law.OptionalLaws
import monocle.Optional
import org.scalaexercises.definitions._
import org.scalatest._

@@ -77,10 +78,10 @@ object OptionalExercises extends FlatSpec with Matchers with Section {
*
* {{{
* head.getOrModify(xs)
* // res2: scalaz.\/[List[Int],Int] = \/-(1)
* // res2: Either[List[Int],Int] = Right(1)
*
* head.getOrModify(ys)
* // res3: scalaz.\/[List[Int],Int] = -\/(List())
* // res3: Either[List[Int],Int] = Left(List())
* }}}
*
* The function `getOrModify` is mostly used for polymorphic optics. If you use monomorphic optics, use function `getOption`
@@ -1,10 +1,12 @@
/*
* scala-exercises - exercises-monocle
* Copyright (C) 2015-2016 47 Degrees, LLC. <http://www.47deg.com>
* scala-exercises - exercises-monocle
* Copyright (C) 2015-2019 47 Degrees, LLC. <http://www.47deg.com>
*
*/

package monocle
package monoclelib

import monocle.Prism
import org.scalaexercises.definitions._
import org.scalatest._

@@ -176,9 +178,9 @@ object PrismExercises extends FlatSpec with Matchers with Section {
*
* == Prism Laws ==
*
* A `Prism` must satisfy all properties defined in `PrismLaws` from the core module. You can check the validity of your own `Prisms` using `PrismTests` from the law module.
* A `Prism` must satisfy all properties defined in `PrismLaws` from the core module. You can check the validity of your own `Prisms` using `PrismTests` from the `law` module.
*
* In particular, a `Prism` must verify that `getOption` and `reverseGet` allow a full round trip if the Prism matches i.e. if `getOption` returns a `Some`.
* In particular, a Prism` must verify that `getOption` and `reverseGet` allow a full round trip if the Prism matches i.e. if `getOption` returns a `Some`.
*
*
*/

0 comments on commit 41f96a2

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