Skip to content
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

Mergemiles #1

Closed
wants to merge 104 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
104 commits
Select commit Hold shift + click to select a range
557ba36
Remove unused Cokleisli.cokleisli method
ceedubs Dec 15, 2015
1a3b465
Check that Cokleisli contramapValue and lmap methods are consistent
ceedubs Dec 15, 2015
34f3817
Minor cleanup to Coproduct
ceedubs Dec 16, 2015
258b289
Merge pull request #756 from ceedubs/coproduct-cleanup
milessabin Dec 16, 2015
0596600
Fix typo in OptionT documentation
exlevan Dec 16, 2015
6fe3e05
Merge pull request #758 from exlevan/master
fthomas Dec 16, 2015
90f40b6
Add ScalaDocs for Option syntax
ceedubs Dec 16, 2015
5aa37e9
Merge pull request #759 from ceedubs/option-syntax-docs
stew Dec 17, 2015
279018e
Merge pull request #753 from ceedubs/cokleisli-contramapValue-test
adelbertc Dec 17, 2015
1c8306c
Add ScalaDoc for some FlatMap syntax
ceedubs Dec 17, 2015
bd28404
Merge pull request #761 from ceedubs/flatmap-docs
adelbertc Dec 17, 2015
fde1d19
Update crossScalaVersions
zaneli Dec 18, 2015
f619620
Remove Kleisli.function method in favor of Kleisli.apply
ceedubs Dec 18, 2015
75891d4
Merge pull request #752 from ceedubs/rm-cokleisli-def
adelbertc Dec 18, 2015
8b6e4ae
Move cats-free and cats-state in to cats-core
DavidGregory084 Dec 18, 2015
50a94c8
Update `travis-publish.sh` removing `free` and `state` project commands
DavidGregory084 Dec 19, 2015
7ccce79
Use SVG for badges
fthomas Dec 20, 2015
962fcab
Remove reference to `free`, `state` modules in docs and fix broken links
DavidGregory084 Dec 21, 2015
d4dc4fa
Improve stack consumption of `Eval.defer`
DavidGregory084 Dec 22, 2015
4a4fcb2
Fix a typo in NotNull
dwijnand Dec 22, 2015
7bdf6f2
Rewrite OptionT.flatMap in terms of flatMapF
dwijnand Dec 22, 2015
b07823f
Dedup orElse/orElseF
dwijnand Dec 23, 2015
213aab0
Merge pull request #767 from fthomas/topic/svg-badges
stew Dec 24, 2015
8d068f7
add Reducible instance for OneAnd, deprecate Foldable instance
aryairani Dec 29, 2015
9c1802e
refactor oneAndReducible to use NonEmptyReducible
aryairani Dec 29, 2015
6253277
Merge pull request #770 from dwijnand/OptionT-flatMap
ceedubs Jan 2, 2016
8566afd
Adds Show[Vector]
mikejcurry Jan 3, 2016
7e7ca84
Adds Show[Stream]
mikejcurry Jan 3, 2016
5311ec5
Merge pull request #764 from zaneli/update-cross-scala-versions
non Jan 4, 2016
9b48dbb
Merge pull request #765 from DavidGregory084/free-state-to-core
non Jan 4, 2016
70200a9
rm dev jekyll config that wasn't working
longcao Dec 21, 2015
70dadfb
fix docs baseurl to not have trailing slash, fixes duped url slashes
longcao Dec 21, 2015
7fe2d24
now without binary compatibility
aryairani Jan 4, 2016
38d4a35
Merge pull request #769 from DavidGregory084/eval-defer-stack-safety
ceedubs Jan 5, 2016
775d630
Remove unused type param on sequence_
ceedubs Jan 5, 2016
971f954
Merge pull request #768 from longcao/fix-docs-duped-url-slashes
ceedubs Jan 5, 2016
2a6e52a
factor out a static inner method from #769 for better GC
aryairani Jan 5, 2016
8b3c015
Merge pull request #775 from mikejcurry/add-stream-show
ceedubs Jan 5, 2016
cb2a945
Merge pull request #774 from mikejcurry/add-vector-show
ceedubs Jan 5, 2016
267721a
Add StateT transformS
adelbertc Jan 5, 2016
caf977f
Merge pull request #778 from ceedubs/rm-type-param-foldable
adelbertc Jan 5, 2016
0857276
Rename SemigroupK.combine to combineK
ceedubs Jan 6, 2016
820cf21
Fix StateT transform comment and add doctest
adelbertc Jan 6, 2016
1f8977b
Merge pull request #780 from adelbertc/state-transformS
ceedubs Jan 6, 2016
81a24d9
Use Eval instead of Trampoline for State
ceedubs Jan 7, 2016
5f0324a
Add ScalaDoc example for foldK syntax
ceedubs Jan 7, 2016
d338150
Remove unused specialized State instance
ceedubs Jan 7, 2016
fc9a75b
Add ScalaDoc examples for Coproduct syntax
ceedubs Jan 7, 2016
30115bc
Make Scaladoc (but not Unidoc) warnings non-fatal
travisbrown Jan 7, 2016
a13f4f7
Merge pull request #787 from travisbrown/topic/cross-module-link-support
ceedubs Jan 8, 2016
2c6abdf
Add ScalaDoc for Either syntax
ceedubs Jan 8, 2016
05add1a
Add ScalaDoc for MonadCombine unite syntax
ceedubs Jan 8, 2016
0529841
Merge pull request #782 from ceedubs/state-eval
adelbertc Jan 8, 2016
8e92896
Add traverseU_ and sequenceU_
adelbertc Jan 10, 2016
a64cd76
Merge pull request #779 from refried/eval-defer-heap-safety
adelbertc Jan 10, 2016
5d87e70
Added scaladoc comments to all the function definitions in cats/arrow…
lukewyman Jan 11, 2016
e4ae734
Merge branch 'master' into topic/arrow-scaladoc
lukewyman Jan 12, 2016
815b8fb
Fix StreamingT.filter bug
ceedubs Jan 12, 2016
ebb92ba
Merge pull request #796 from adelbertc/foldable-unapply-syntax
ceedubs Jan 12, 2016
ceff342
Merge pull request #798 from ceedubs/streamingt-filter-bug
ceedubs Jan 12, 2016
61f148a
fixed a typo in scaladoc comment on cat/arrow/Arrow
lukewyman Jan 12, 2016
591555f
Merge pull request #797 from lukewyman/topic/arrow-scaladoc
ceedubs Jan 13, 2016
d85cf4f
Change Monoidal to Cartesian, add new Applicative laws to test for pr…
adelbertc Jan 10, 2016
56dede8
Fix order of effects in FreeApplicative.foldMap
ceedubs Jan 13, 2016
3d2ffa9
Merge pull request #801 from ceedubs/freeapp-effect-order
non Jan 14, 2016
d8f33c8
Merge pull request #790 from ceedubs/monadcombine-syntax-docs
non Jan 14, 2016
a2253a1
Merge pull request #789 from ceedubs/either-syntax-docs
non Jan 14, 2016
f94b439
Merge pull request #784 from ceedubs/coproduct-syntax-docs
non Jan 14, 2016
0c0379e
Merge pull request #783 from ceedubs/foldK-example
non Jan 14, 2016
45c0be4
Add XorT#valueOr
notxcain Jan 15, 2016
07d0cd1
Add test for XorT#valueOr
notxcain Jan 15, 2016
d4f896a
Prettify XorT#recoverWith
notxcain Jan 15, 2016
35e376b
Merge pull request #807 from notxcain/xort-valueor
ceedubs Jan 15, 2016
d6dce55
Merge pull request #808 from notxcain/prettify-recoverwith
non Jan 15, 2016
e40759a
Merge remote-tracking branch 'upstream/master' into monoidal-redux
adelbertc Jan 15, 2016
312afa7
Add ApplicativeError
travisbrown Jan 18, 2016
15a5e8d
Merge pull request #812 from travisbrown/topic/applicative-error
adelbertc Jan 18, 2016
dc66996
Merge remote-tracking branch 'upstream/master' into monoidal-redux
adelbertc Jan 18, 2016
2fc1444
Update Monad/ApplicativeError tests w/ Cartesian changes
adelbertc Jan 18, 2016
9f16d2f
Add Traverse instance for OneAnd
notxcain Jan 18, 2016
7263202
Add test for Traverse[OneAnd[F, ?]]
notxcain Jan 18, 2016
49190b0
Add serializability test for Traverse[OneAnd[F, ?]]
notxcain Jan 18, 2016
96e92b9
Fix test name
notxcain Jan 19, 2016
61cc646
Monoidal laws defined independent of Functor
adelbertc Jan 19, 2016
4a656d1
Remove unnecessary imaps in CartesianTests
adelbertc Jan 19, 2016
0864952
cats#813 - Adds CoflatMap type class to the Vector Instance
juanpedromoreno Jan 18, 2016
5d87506
cats#813 - Provides CoflatMap tests for VectorTests
juanpedromoreno Jan 18, 2016
4da172f
cats#813 - Removes non-necessary import
juanpedromoreno Jan 19, 2016
c20f6ed
cats#813 - Changes the coflatMap implementation in order to use ListB…
juanpedromoreno Jan 19, 2016
7ee5f2f
cats#813 - Addresses a code review comment, changing the coflatMap im…
juanpedromoreno Jan 19, 2016
4c714fd
Update list of authors
fthomas Jan 19, 2016
06eeb68
Merge pull request #818 from 47deg/juanpedromoreno-adds-coflatmap-typ…
fthomas Jan 19, 2016
cf1c528
Merge remote-tracking branch 'upstream/master' into monoidal-redux
adelbertc Jan 19, 2016
f3c4eba
Upgrade to simulacrum 0.6.1, which makes type classes universal and s…
mpilquist Jan 20, 2016
722ce05
Merge pull request #819 from fthomas/topic/update-authors
milessabin Jan 20, 2016
d8e7e78
Merge pull request #820 from mpilquist/topic/simulacrum-upgrade
milessabin Jan 20, 2016
03f625a
Fix two small errors in OptionT docs
rgcase Jan 25, 2016
acbe54e
Merge pull request #816 from notxcain/master
ceedubs Jan 26, 2016
6dc0c32
Merge pull request #825 from rgcase/optionTDocs
ceedubs Jan 26, 2016
0eaf692
Merge remote-tracking branch 'upstream/master' into monoidal-redux
adelbertc Jan 27, 2016
9780e8f
Merge pull request #795 from adelbertc/monoidal-redux
adelbertc Jan 27, 2016
ba77953
Merge pull request #772 from refried/oneand-reducible
mpilquist Jan 30, 2016
33642a0
Merge pull request #781 from ceedubs/combineK
ceedubs Jan 30, 2016
87c85bf
Merge remote-tracking branch 'miles/master' into mergemiles
stew Jan 30, 2016
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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ git:
depth: 9999

scala:
- 2.10.5
- 2.10.6
- 2.11.7

cache:
Expand Down
21 changes: 20 additions & 1 deletion AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,47 +14,66 @@ possible:

* Adelbert Chang
* Alessandro Lacava
* Alexey Levan
* Alissa Pajer
* Alistair Johnson
* Amir Mohammad Saied
* Andrew Jones
* Antoine Comte
* Arya Irani
* Ash Pook
* Benjamin Thuillier
* Bobby
* Bobby Rauchenberg
* Brendan McAdams
* Cody Allen
* Colt Frederickson
* Dale Wijnand
* Dave Rostron
* David Allsopp
* David Gregory
* Denis Mikhaylov
* Derek Wickern
* Edmund Noble
* Erik LaBianca
* Erik Osheim
* Eugene Burmako
* Eugene Yokota
* Feynman Liang
* Frank S. Thomas
* Jean-Rémi Desjardins
* Jisoo Park
* Josh Marcus
* Julien Richard-Foy
* Julien Truffaut
* Kenji Yoshida
* Long Cao
* Luis Angel Vicente Sanchez
* Luke Wyman
* Marc Siegel
* Markus Hauck
* Matthias Lüneberg
* Michael Pilquist
* Mike Curry
* Miles Sabin
* Olli Helenius
* Owen Parry
* Pascal Voitot
* Paul Phillips
* Philip Wills
* Raúl Raja Martínez
* Rintcius Blok
* Rob Norris
* Romain Ruetschi
* Ross A. Baker
* Sarunas Valaskevicius
* Shunsuke Otani
* Sinisa Louc
* Stephen Judkins
* Stew O'Connor
* Sumedh Mungee
* Travis Brown
* Wedens
* Yosef Fertel
* Zach Abbott

We've tried to include everyone, but if you've made a contribution to
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ Write about https://github.com/non/cats/pull/36#issuecomment-72892359
### Write tests

- Tests for cats-core go into the tests module, under the `cats.tests` package.
- Tests for additional modules, such as `free`, go into the tests directory within that module.
- Tests for additional modules, such as 'jvm', go into the tests directory within that module.
- Cats tests should extend `CatsSuite`. `CatsSuite` integrates [ScalaTest](http://www.scalatest.org/)
with [Discipline](https://github.com/typelevel/discipline) for law checking, and imports all syntax and standard instances for convenience.
- The first parameter to the `checkAll` method provided by
Expand Down
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## Cats

[![Build Status](https://api.travis-ci.org/non/cats.png)](https://travis-ci.org/non/cats)
[![Workflow](https://badge.waffle.io/non/cats.png?label=ready&title=Ready)](https://waffle.io/non/cats)
[![Build Status](https://api.travis-ci.org/non/cats.svg)](https://travis-ci.org/non/cats)
[![Workflow](https://badge.waffle.io/non/cats.svg?label=ready&title=Ready)](https://waffle.io/non/cats)
[![Chat](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/non/cats)
[![codecov.io](http://codecov.io/github/non/cats/coverage.svg?branch=master)](http://codecov.io/github/non/cats?branch=master)
[![Maven Central](https://img.shields.io/maven-central/v/org.spire-math/cats_2.11.svg)](https://maven-badges.herokuapp.com/maven-central/org.spire-math/cats_2.11)
Expand Down Expand Up @@ -33,8 +33,6 @@ functionality, you can pick-and-choose from amongst these modules
* `cats-macros`: Macros used by Cats syntax (*required*).
* `cats-core`: Core type classes and functionality (*required*).
* `cats-laws`: Laws for testing type class instances.
* `cats-free`: "Free" data constructors for various type classes.
* `cats-state`: Monad and transformer support for state.

Release notes for Cats are available in [CHANGES.md](CHANGES.md).

Expand Down Expand Up @@ -113,8 +111,6 @@ Initially Cats will support the following modules:
* `macros`: Macro definitions needed for `core` and other projects.
* `core`: Definitions for widely-used type classes and data types.
* `laws`: The encoded laws for type classes, exported to assist third-party testing.
* `free`: "Free" data constructors for various type classes.
* `state`: Monad and transformer support for state.
* `tests`: Verifies the laws, and runs any other tests. Not published.

As the type class families grow, it's possible that additional modules
Expand Down
46 changes: 14 additions & 32 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ lazy val scoverageSettings = Seq(
lazy val buildSettings = Seq(
organization := "org.spire-math",
scalaVersion := "2.11.7",
crossScalaVersions := Seq("2.10.5", "2.11.7")
crossScalaVersions := Seq("2.10.6", "2.11.7")
)

lazy val catsDoctestSettings = Seq(
Expand All @@ -30,14 +30,15 @@ lazy val commonSettings = Seq(
Resolver.sonatypeRepo("snapshots")
),
libraryDependencies ++= Seq(
"com.github.mpilquist" %%% "simulacrum" % "0.5.0",
"com.github.mpilquist" %%% "simulacrum" % "0.6.1",
"org.spire-math" %%% "algebra" % "0.3.1",
"org.spire-math" %%% "algebra-std" % "0.3.1",
"org.typelevel" %%% "machinist" % "0.4.1",
compilerPlugin("org.scalamacros" %% "paradise" % "2.1.0-M5" cross CrossVersion.full),
compilerPlugin("org.spire-math" %% "kind-projector" % "0.6.3")
),
parallelExecution in Test := false
parallelExecution in Test := false,
scalacOptions in (Compile, doc) := (scalacOptions in (Compile, doc)).value.filter(_ != "-Xfatal-warnings")
) ++ warnUnusedImport

lazy val commonJsSettings = Seq(
Expand All @@ -62,12 +63,13 @@ lazy val disciplineDependencies = Seq(

lazy val docSettings = Seq(
autoAPIMappings := true,
unidocProjectFilter in (ScalaUnidoc, unidoc) := inProjects(coreJVM, freeJVM, stateJVM),
unidocProjectFilter in (ScalaUnidoc, unidoc) := inProjects(coreJVM),
site.addMappingsToSiteDir(mappings in (ScalaUnidoc, packageDoc), "api"),
site.addMappingsToSiteDir(tut, "_tut"),
ghpagesNoJekyll := false,
siteMappings += file("CONTRIBUTING.md") -> "contributing.md",
scalacOptions in (ScalaUnidoc, unidoc) ++= Seq(
"-Xfatal-warnings",
"-doc-source-url", scmInfo.value.get.browseUrl + "/tree/master€{FILE_PATH}.scala",
"-sourcepath", baseDirectory.in(LocalRootProject).value.getAbsolutePath,
"-diagrams"
Expand All @@ -87,7 +89,7 @@ lazy val docs = project
.settings(tutSettings)
.settings(tutScalacOptions ~= (_.filterNot(Set("-Ywarn-unused-import", "-Ywarn-dead-code"))))
.settings(commonJvmSettings)
.dependsOn(coreJVM, freeJVM, stateJVM)
.dependsOn(coreJVM)

lazy val cats = project.in(file("."))
.settings(moduleName := "root")
Expand All @@ -100,15 +102,15 @@ lazy val catsJVM = project.in(file(".catsJVM"))
.settings(moduleName := "cats")
.settings(catsSettings)
.settings(commonJvmSettings)
.aggregate(macrosJVM, coreJVM, lawsJVM, freeJVM, stateJVM, testsJVM, jvm, docs, bench)
.dependsOn(macrosJVM, coreJVM, lawsJVM, freeJVM, stateJVM, testsJVM % "test-internal -> test", jvm, bench % "compile-internal;test-internal -> test")
.aggregate(macrosJVM, coreJVM, lawsJVM, testsJVM, jvm, docs, bench)
.dependsOn(macrosJVM, coreJVM, lawsJVM, testsJVM % "test-internal -> test", jvm, bench % "compile-internal;test-internal -> test")

lazy val catsJS = project.in(file(".catsJS"))
.settings(moduleName := "cats")
.settings(catsSettings)
.settings(commonJsSettings)
.aggregate(macrosJS, coreJS, lawsJS, freeJS, stateJS, testsJS, js)
.dependsOn(macrosJS, coreJS, lawsJS, freeJS, stateJS, testsJS % "test-internal -> test", js)
.aggregate(macrosJS, coreJS, lawsJS, testsJS, js)
.dependsOn(macrosJS, coreJS, lawsJS, testsJS % "test-internal -> test", js)
.enablePlugins(ScalaJSPlugin)


Expand Down Expand Up @@ -151,26 +153,6 @@ lazy val laws = crossProject.crossType(CrossType.Pure)
lazy val lawsJVM = laws.jvm
lazy val lawsJS = laws.js

lazy val free = crossProject.crossType(CrossType.Pure)
.dependsOn(macros, core, tests % "test-internal -> test")
.settings(moduleName := "cats-free")
.settings(catsSettings:_*)
.jsSettings(commonJsSettings:_*)
.jvmSettings(commonJvmSettings:_*)

lazy val freeJVM = free.jvm
lazy val freeJS = free.js

lazy val state = crossProject.crossType(CrossType.Pure)
.dependsOn(macros, core, free % "compile-internal;test-internal -> test", tests % "test-internal -> test")
.settings(moduleName := "cats-state")
.settings(catsSettings:_*)
.jsSettings(commonJsSettings:_*)
.jvmSettings(commonJvmSettings:_*)

lazy val stateJVM = state.jvm
lazy val stateJS = state.js

lazy val tests = crossProject.crossType(CrossType.Pure)
.dependsOn(macros, core, laws)
.settings(moduleName := "cats-tests")
Expand All @@ -194,7 +176,7 @@ lazy val jvm = project
.settings(commonJvmSettings:_*)

// bench is currently JVM-only
lazy val bench = project.dependsOn(macrosJVM, coreJVM, freeJVM, lawsJVM)
lazy val bench = project.dependsOn(macrosJVM, coreJVM, lawsJVM)
.settings(moduleName := "cats-bench")
.settings(catsSettings)
.settings(noPublishSettings)
Expand Down Expand Up @@ -227,11 +209,11 @@ lazy val publishSettings = Seq(
) ++ credentialSettings ++ sharedPublishSettings ++ sharedReleaseProcess

// These aliases serialise the build for the benefit of Travis-CI.
addCommandAlias("buildJVM", ";macrosJVM/compile;coreJVM/compile;coreJVM/test;freeJVM/compile;freeJVM/test;stateJVM/compile;stateJVM/test;lawsJVM/compile;testsJVM/test;jvm/test;bench/test")
addCommandAlias("buildJVM", ";macrosJVM/compile;coreJVM/compile;coreJVM/test;lawsJVM/compile;testsJVM/test;jvm/test;bench/test")

addCommandAlias("validateJVM", ";scalastyle;buildJVM;makeSite")

addCommandAlias("validateJS", ";macrosJS/compile;coreJS/compile;lawsJS/compile;testsJS/test;js/test;freeJS/compile;freeJS/test;stateJS/compile;stateJS/test")
addCommandAlias("validateJS", ";macrosJS/compile;coreJS/compile;lawsJS/compile;testsJS/test;js/test")

addCommandAlias("validate", ";validateJS;validateJVM")

Expand Down
81 changes: 81 additions & 0 deletions core/src/main/scala/cats/ApplicativeError.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package cats

import cats.data.{Xor, XorT}

/**
* An applicative that also allows you to raise and or handle an error value.
*
* This type class allows one to abstract over error-handling applicatives.
*/
trait ApplicativeError[F[_], E] extends Applicative[F] {
/**
* Lift an error into the `F` context.
*/
def raiseError[A](e: E): F[A]

/**
* Handle any error, potentially recovering from it, by mapping it to an
* `F[A]` value.
*
* @see [[handleError]] to handle any error by simply mapping it to an `A`
* value instead of an `F[A]`.
*
* @see [[recoverWith]] to recover from only certain errors.
*/
def handleErrorWith[A](fa: F[A])(f: E => F[A]): F[A]

/**
* Handle any error, by mapping it to an `A` value.
*
* @see [[handleErrorWith]] to map to an `F[A]` value instead of simply an
* `A` value.
*
* @see [[recover]] to only recover from certain errors.
*/
def handleError[A](fa: F[A])(f: E => A): F[A] = handleErrorWith(fa)(f andThen pure)

/**
* Handle errors by turning them into [[cats.data.Xor.Left]] values.
*
* If there is no error, then an [[cats.data.Xor.Right]] value will be returned instead.
*
* All non-fatal errors should be handled by this method.
*/
def attempt[A](fa: F[A]): F[E Xor A] = handleErrorWith(
map(fa)(Xor.right[E, A])
)(e => pure(Xor.left(e)))

/**
* Similar to [[attempt]], but wraps the result in a [[cats.data.XorT]] for
* convenience.
*/
def attemptT[A](fa: F[A]): XorT[F, E, A] = XorT(attempt(fa))

/**
* Recover from certain errors by mapping them to an `A` value.
*
* @see [[handleError]] to handle any/all errors.
*
* @see [[recoverWith]] to recover from certain errors by mapping them to
* `F[A]` values.
*/
def recover[A](fa: F[A])(pf: PartialFunction[E, A]): F[A] =
handleErrorWith(fa)(e =>
(pf andThen pure) applyOrElse(e, raiseError))

/**
* Recover from certain errors by mapping them to an `F[A]` value.
*
* @see [[handleErrorWith]] to handle any/all errors.
*
* @see [[recover]] to recover from certain errors by mapping them to `A`
* values.
*/
def recoverWith[A](fa: F[A])(pf: PartialFunction[E, F[A]]): F[A] =
handleErrorWith(fa)(e =>
pf applyOrElse(e, raiseError))
}

object ApplicativeError {
def apply[F[_], E](implicit F: ApplicativeError[F, E]): ApplicativeError[F, E] = F
}
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/Apply.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import simulacrum.typeclass
* Must obey the laws defined in cats.laws.ApplyLaws.
*/
@typeclass(excludeParents=List("ApplyArityFunctions"))
trait Apply[F[_]] extends Functor[F] with Monoidal[F] with ApplyArityFunctions[F] { self =>
trait Apply[F[_]] extends Functor[F] with Cartesian[F] with ApplyArityFunctions[F] { self =>

/**
* Given a value and a function in the Apply context, applies the
Expand Down
19 changes: 19 additions & 0 deletions core/src/main/scala/cats/Cartesian.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package cats

import simulacrum.typeclass

/**
* [[Cartesian]] captures the idea of composing independent effectful values.
* It is of particular interest when taken together with [[Functor]] - where [[Functor]]
* captures the idea of applying a unary pure function to an effectful value,
* calling `product` with `map` allows one to apply a function of arbitrary arity to multiple
* independent effectful values.
*
* That same idea is also manifested in the form of [[Apply]], and indeed [[Apply]] extends both
* [[Cartesian]] and [[Functor]] to illustrate this.
*/
@typeclass trait Cartesian[F[_]] {
def product[A, B](fa: F[A], fb: F[B]): F[(A, B)]
}

object Cartesian extends CartesianArityFunctions
19 changes: 17 additions & 2 deletions core/src/main/scala/cats/Eval.scala
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,23 @@ object Eval extends EvalInstances {
* they will be automatically created when needed.
*/
sealed abstract class Call[A](val thunk: () => Eval[A]) extends Eval[A] {
def memoize: Eval[A] = new Later(() => thunk().value)
def value: A = thunk().value
def memoize: Eval[A] = new Later(() => value)
def value: A = Call.loop(this).value
}

object Call {
/** Collapse the call stack for eager evaluations */
private def loop[A](fa: Eval[A]): Eval[A] = fa match {
case call: Eval.Call[A] =>
loop(call.thunk())
case compute: Eval.Compute[A] =>
new Eval.Compute[A] {
type Start = compute.Start
val start: () => Eval[Start] = () => compute.start()
val run: Start => Eval[A] = s => loop(compute.run(s))
}
case other => other
}
}

/**
Expand Down
Loading