Skip to content

Adds minor upgrade to stdlib exercises #149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 19, 2019
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
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
dist: xenial
language: scala
scala:
- 2.11.11
- 2.11.12
jdk:
- oraclejdk8
- openjdk8
script:
- sbt test

Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
val scalaExercisesV = "0.4.0-SNAPSHOT"

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

lazy val stdlib = (project in file("."))
.enablePlugins(ExerciseCompilerPlugin)
Expand Down
16 changes: 13 additions & 3 deletions project/ProjectPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ object ProjectPlugin extends AutoPlugin {

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

object autoImport {

lazy val V = new {
val scala211: String = "2.11.12"
}
}

import autoImport._


override def projectSettings: Seq[Def.Setting[_]] =
Seq(
description := "Scala Exercises: The path to enlightenment",
Expand All @@ -25,9 +35,9 @@ object ProjectPlugin extends AutoPlugin {
organizationEmail = "hello@47deg.com"
),
orgLicenseSetting := ApacheLicense,
scalaVersion := "2.11.11",
scalaVersion := V.scala211,
scalaOrganization := "org.scala-lang",
crossScalaVersions := Seq("2.11.11"),
crossScalaVersions := Seq(V.scala211),
resolvers ++= Seq(
Resolver.mavenLocal,
Resolver.sonatypeRepo("snapshots"),
Expand All @@ -41,7 +51,7 @@ object ProjectPlugin extends AutoPlugin {
| * Copyright (C) 2015-2016 47 Degrees, LLC. <http://www.47deg.com>
| */
|
|""".stripMargin)
|""".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.13
sbt.version=0.13.15
6 changes: 3 additions & 3 deletions src/main/scala/stdlib/HigherOrderFunctions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ object HigherOrderFunctions
}

/** And then we get to Higher Order Functions:
* Higher Order Functions are functions that take functions as arguments and/or return functions.
*
* We can take that closure and throw it into a Higher Order Function and it will still hold the environment:
* Higher Order Functions are functions that take functions as arguments and/or return functions.
*
* We can take that closure and throw it into a Higher Order Function and it will still hold the environment:
*/
def holdEnvironmentHigherOrderFunctions(res0: Int, res1: Int) {
def summation(x: Int, y: Int ⇒ Int) = y(x)
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/stdlib/Ranges.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ object Ranges extends FlatSpec with Matchers with org.scalaexercises.definitions
/** A Range is an ordered sequence of integers that are equally spaced apart. For example, "1, 2, 3" is a range, as is "5, 8, 11, 14". To create a range in Scala, use the predefined methods `to`, `until`, and `by`. `1 to 3` generates "1, 2, 3" and `5 to 14 by 3` generates "5, 8, 11, 14".
*
* If you want to create a range that is exclusive of its upper limit, then use `until` instead of `to`: `1 until 3` generates "1, 2".
*
*
* Note that `Range(a, b, c)` is the same as `a until b by c`
*
* Ranges are represented in constant space, because they can be defined by just three numbers: their start, their end, and the stepping value. Because of this representation, most operations on ranges are extremely fast.
Expand Down
17 changes: 8 additions & 9 deletions src/main/scala/stdlib/Traits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -100,22 +100,21 @@ object Traits extends FlatSpec with Matchers with org.scalaexercises.definitions
myListener.isInstanceOf[Any] should be(res2)
myListener.isInstanceOf[AnyRef] should be(res3)
}

/** Traits also can use self-types. A self-type lists the required dependencies for mixing in the trait. When mixing in the main trait, all self-type dependencies of that trait must also be mixed in, otherwise a compile-time error is thrown.
*
*
* Also, the dependencies can't have identical method/property names or else you'll get an `illegal inheritance` error.
*/
def selfTypeTraits(res0: Int){
def selfTypeTraits(res0: Int) {
trait B {
def bId = 2
}

trait A {
self: B =>

}

trait A { self: B =>

def aId = 1
}

//val a = new A //***does not compile!!!***
val obj = new A with B
(obj.aId + obj.bId) should be(res0)
Expand Down
6 changes: 3 additions & 3 deletions src/main/scala/stdlib/Traversables.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ object Traversables extends FlatSpec with Matchers with org.scalaexercises.defin
*
* The `foreach` method is meant to traverse all elements of the collection, and apply the given operation, `f`, to each element. The type of the operation is `Elem => U`, where `Elem` is the type of the collection's elements and `U` is an arbitrary result type. The invocation of `f` is done for its side effect only; in fact any function result of `f` is discarded by `foreach`.
*
* Traversables are the superclass of `List`, `Array`, `Map`, `Set`, `Stream` and more. The methods involved can be applied to each other in a different type.
* Traversables are the superclass of `List`, `Array`, `Map`, `Set`, `Stream` and more. The methods involved can be applied to each other in a different type.
`++` appends two `Traversable`s together. The resulting `Traversable` is the same type of the first element.
*/
def topOfCollectionTraversables(res0: Int, res1: Int) {
Expand Down Expand Up @@ -514,8 +514,8 @@ object Traversables extends FlatSpec with Matchers with org.scalaexercises.defin
/** The naive recursive implementation of `reduceRight` is not tail recursive and would lead to a stack overflow if used on larger traversables.
* However, `reduceLeft` can be implemented with tail recursion.
*
* To avoid the potential stack overflow with the naive implementation of `reduceRight` we can easily implement it based on `reduceLeft` by reverting the list and the inverting the reduce function.
* The same applies for folding operations.
* To avoid the potential stack overflow with the naive implementation of `reduceRight` we can easily implement it based on `reduceLeft` by reverting the list and the inverting the reduce function.
* The same applies for folding operations.
*
* There is also a `reduce` (and `fold`) available, which works exactly like `reduceLeft` (and `foldLeft`) and it should be the prefered method to call unless there is a strong reason to use `reduceRight` (or `foldRight`).
*/
Expand Down
2 changes: 1 addition & 1 deletion version.sbt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version in ThisBuild := "0.4.2-SNAPSHOT"
version in ThisBuild := "0.5.0-SNAPSHOT"