-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feature/translift-expression
- Loading branch information
Showing
31 changed files
with
422 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ project/boot | |
target | ||
.ensime | ||
.ensime_lucene | ||
.ensime_cache | ||
TAGS | ||
\#*# | ||
*~ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,8 @@ import sbtunidoc.Plugin.UnidocKeys._ | |
import ReleaseTransformations._ | ||
import ScoverageSbtPlugin._ | ||
|
||
lazy val botBuild = settingKey[Boolean]("Build by TravisCI instead of local dev environment") | ||
|
||
lazy val scoverageSettings = Seq( | ||
ScoverageKeys.coverageMinimum := 60, | ||
ScoverageKeys.coverageFailOnMinimum := false, | ||
|
@@ -55,7 +57,15 @@ lazy val commonJsSettings = Seq( | |
s"-P:scalajs:mapSourceURI:$a->$g/" | ||
}, | ||
scalaJSStage in Global := FastOptStage, | ||
parallelExecution := false | ||
parallelExecution := false, | ||
// Using Rhino as jsEnv to build scala.js code can lead to OOM, switch to PhantomJS by default | ||
scalaJSUseRhino := false, | ||
requiresDOM := false, | ||
jsEnv := NodeJSEnv().value, | ||
// Only used for scala.js for now | ||
botBuild := sys.props.getOrElse("CATS_BOT_BUILD", default="false") == "true", | ||
// batch mode decreases the amount of memory needed to compile scala.js code | ||
scalaJSOptimizerOptions := scalaJSOptimizerOptions.value.withBatchMode(botBuild.value) | ||
) | ||
|
||
lazy val commonJvmSettings = Seq( | ||
|
@@ -73,9 +83,21 @@ lazy val disciplineDependencies = Seq( | |
libraryDependencies += "org.typelevel" %%% "discipline" % "0.4" | ||
) | ||
|
||
/** | ||
* Remove 2.10 projects from doc generation, as the macros used in the projects | ||
* cause problems generating the documentation on scala 2.10. As the APIs for 2.10 | ||
* and 2.11 are the same this has no effect on the resultant documentation, though | ||
* it does mean that the scaladocs cannot be generated when the build is in 2.10 mode. | ||
*/ | ||
def noDocProjects(sv: String): Seq[ProjectReference] = CrossVersion.partialVersion(sv) match { | ||
case Some((2, 10)) => Seq[ProjectReference](coreJVM) | ||
case _ => Nil | ||
} | ||
|
||
lazy val docSettings = Seq( | ||
autoAPIMappings := true, | ||
unidocProjectFilter in (ScalaUnidoc, unidoc) := inProjects(coreJVM), | ||
unidocProjectFilter in (ScalaUnidoc, unidoc) := | ||
inProjects(coreJVM) -- inProjects(noDocProjects(scalaVersion.value): _*), | ||
site.addMappingsToSiteDir(mappings in (ScalaUnidoc, packageDoc), "api"), | ||
site.addMappingsToSiteDir(tut, "_tut"), | ||
ghpagesNoJekyll := false, | ||
|
@@ -209,6 +231,12 @@ lazy val publishSettings = Seq( | |
scmInfo := Some(ScmInfo(url("https://github.com/typelevel/cats"), "scm:git:[email protected]:typelevel/cats.git")), | ||
autoAPIMappings := true, | ||
apiURL := Some(url("http://typelevel.org/cats/api/")), | ||
publishArtifact in (Compile, packageDoc) := { | ||
CrossVersion.partialVersion(scalaVersion.value) match { | ||
case Some((2, 10)) => false // don't package scaladoc when publishing for 2.10 | ||
case _ => true | ||
} | ||
}, | ||
pomExtra := ( | ||
<developers> | ||
<developer> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package cats | ||
package syntax | ||
|
||
import cats.data.{Xor, XorT} | ||
|
||
trait ApplicativeErrorSyntax { | ||
implicit def applicativeErrorIdSyntax[E](e: E): ApplicativeErrorIdOps[E] = | ||
new ApplicativeErrorIdOps(e) | ||
|
||
implicit def applicativeErrorSyntax[F[_, _], E, A](fa: F[E, A])(implicit F: ApplicativeError[F[E, ?], E]): ApplicativeErrorOps[F[E, ?], E, A] = | ||
new ApplicativeErrorOps[F[E, ?], E, A](fa) | ||
} | ||
|
||
final class ApplicativeErrorIdOps[E](e: E) { | ||
def raiseError[F[_], A](implicit F: ApplicativeError[F, E]): F[A] = | ||
F.raiseError(e) | ||
} | ||
|
||
final class ApplicativeErrorOps[F[_], E, A](fa: F[A])(implicit F: ApplicativeError[F, E]) { | ||
def handleError(f: E => A): F[A] = | ||
F.handleError(fa)(f) | ||
|
||
def handleErrorWith(f: E => F[A]): F[A] = | ||
F.handleErrorWith(fa)(f) | ||
|
||
def attempt: F[E Xor A] = | ||
F.attempt(fa) | ||
|
||
def attemptT: XorT[F, E, A] = | ||
F.attemptT(fa) | ||
|
||
def recover(pf: PartialFunction[E, A]): F[A] = | ||
F.recover(fa)(pf) | ||
|
||
def recoverWith(pf: PartialFunction[E, F[A]]): F[A] = | ||
F.recoverWith(fa)(pf) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
tests/src/test/scala/cats/tests/ApplicativeErrorTests.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package cats | ||
package tests | ||
|
||
import cats.data.{Xor, XorT} | ||
|
||
class ApplicativeErrorCheck extends CatsSuite { | ||
|
||
type ErrorOr[A] = String Xor A | ||
|
||
val failed: String Xor Int = | ||
"Badness".raiseError[ErrorOr, Int] | ||
|
||
test("raiseError syntax creates an Xor with the correct type parameters") { | ||
failed should === ("Badness".left[Int]) | ||
} | ||
|
||
test("handleError syntax transforms an error to a success") { | ||
failed.handleError(error => error.length) should === (7.right) | ||
} | ||
|
||
test("handleErrorWith transforms an error to a success") { | ||
failed.handleErrorWith(error => error.length.right) should === (7.right) | ||
} | ||
|
||
test("attempt syntax creates a wrapped Xor") { | ||
failed.attempt should === ("Badness".left.right) | ||
} | ||
|
||
test("attemptT syntax creates an XorT") { | ||
failed.attemptT should === (XorT[ErrorOr, String, Int](failed.right)) | ||
} | ||
|
||
test("recover syntax transforms an error to a success") { | ||
failed.recover { case error => error.length } should === (7.right) | ||
} | ||
|
||
test("recoverWith transforms an error to a success") { | ||
failed.recoverWith { case error => error.length.right } should === (7.right) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package cats | ||
package tests | ||
|
||
import cats.data.Xor | ||
import cats.laws.discipline.{BifoldableTests, SerializableTests} | ||
import cats.laws.discipline.arbitrary._ | ||
|
||
class BifoldableTest extends CatsSuite { | ||
type EitherXor[A, B] = Either[Xor[A, B], Xor[A, B]] | ||
val eitherComposeXor: Bifoldable[EitherXor] = | ||
Bifoldable[Either].compose[Xor] | ||
|
||
checkAll("Either compose Xor", BifoldableTests(eitherComposeXor).bifoldable[Int, Int, Int]) | ||
checkAll("Bifoldable[Either compose Xor]", SerializableTests.serializable(eitherComposeXor)) | ||
} |
Oops, something went wrong.