-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Use simulacrum for typeclass boilerplate #806
Merged
Merged
Changes from all commits
Commits
Show all changes
53 commits
Select commit
Hold shift + click to select a range
2a6e52a
factor out a static inner method from #769 for better GC
aryairani 81a24d9
Use Eval instead of Trampoline for State
ceedubs 5f0324a
Add ScalaDoc example for foldK syntax
ceedubs d338150
Remove unused specialized State instance
ceedubs fc9a75b
Add ScalaDoc examples for Coproduct syntax
ceedubs 2c6abdf
Add ScalaDoc for Either syntax
ceedubs 05add1a
Add ScalaDoc for MonadCombine unite syntax
ceedubs 0529841
Merge pull request #782 from ceedubs/state-eval
adelbertc 8e92896
Add traverseU_ and sequenceU_
adelbertc a64cd76
Merge pull request #779 from refried/eval-defer-heap-safety
adelbertc 5d87e70
Added scaladoc comments to all the function definitions in cats/arrow…
lukewyman e4ae734
Merge branch 'master' into topic/arrow-scaladoc
lukewyman 815b8fb
Fix StreamingT.filter bug
ceedubs ebb92ba
Merge pull request #796 from adelbertc/foldable-unapply-syntax
ceedubs ceff342
Merge pull request #798 from ceedubs/streamingt-filter-bug
ceedubs 61f148a
fixed a typo in scaladoc comment on cat/arrow/Arrow
lukewyman 591555f
Merge pull request #797 from lukewyman/topic/arrow-scaladoc
ceedubs 56dede8
Fix order of effects in FreeApplicative.foldMap
ceedubs 3d2ffa9
Merge pull request #801 from ceedubs/freeapp-effect-order
non d8f33c8
Merge pull request #790 from ceedubs/monadcombine-syntax-docs
non a2253a1
Merge pull request #789 from ceedubs/either-syntax-docs
non f94b439
Merge pull request #784 from ceedubs/coproduct-syntax-docs
non 0c0379e
Merge pull request #783 from ceedubs/foldK-example
non 95f0897
Hide simulacrum dependency from the .pom
rklaehn 1b9d2f1
Remove machinist dependency from cats-kernel
rklaehn 289484c
Use @typeclass annotation for Eq typeclass
rklaehn b8c686a
Add typeclass annotation to Semigroup and Monoid
rklaehn 66d485f
Add typeclass annotation to Group
rklaehn b33c9de
Add typeclass annotation to Order and PartialOrder
rklaehn 0bba290
Fixed another compile error due to missing override
rklaehn 8cbf29f
Remove reference to algebra in docs and adjust source paths
rklaehn b868421
Added stubs for documentation of remaining cats-kernel typeclasses
rklaehn 45c0be4
Add XorT#valueOr
notxcain 07d0cd1
Add test for XorT#valueOr
notxcain d4f896a
Prettify XorT#recoverWith
notxcain 35e376b
Merge pull request #807 from notxcain/xort-valueor
ceedubs d6dce55
Merge pull request #808 from notxcain/prettify-recoverwith
non e0cd78c
Use "provided" instead of "compileonly" for simulacrum
rklaehn bfa8727
Remove "provided" dependencies
rklaehn 312afa7
Add ApplicativeError
travisbrown 15a5e8d
Merge pull request #812 from travisbrown/topic/applicative-error
adelbertc 0864952
cats#813 - Adds CoflatMap type class to the Vector Instance
juanpedromoreno 5d87506
cats#813 - Provides CoflatMap tests for VectorTests
juanpedromoreno 4da172f
cats#813 - Removes non-necessary import
juanpedromoreno c20f6ed
cats#813 - Changes the coflatMap implementation in order to use ListB…
juanpedromoreno 7ee5f2f
cats#813 - Addresses a code review comment, changing the coflatMap im…
juanpedromoreno 4c714fd
Update list of authors
fthomas 06eeb68
Merge pull request #818 from 47deg/juanpedromoreno-adds-coflatmap-typ…
fthomas f3c4eba
Upgrade to simulacrum 0.6.1, which makes type classes universal and s…
mpilquist 722ce05
Merge pull request #819 from fthomas/topic/update-authors
milessabin d8e7e78
Merge pull request #820 from mpilquist/topic/simulacrum-upgrade
milessabin 69ad4e4
Merge branch 'master' into topic/kernel
rklaehn 87f2f3c
Fix merge conflict caused by the addition of mima to the kernel project.
rklaehn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,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 | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can this be compile only? I guess not or you would have done so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that machinistDependencies are only used in cats-core, not in cats-kernel. I don't know if this can be compile-only, but I did not want to mess with things other than cats-kernel for this PR.
cats-kernel does not have a dep on machinist for now. See pom.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh yes. Sorry. LGTM.
On Thu, Jan 14, 2016 at 2:23 PM, Rüdiger Klaehn notifications@github.com
wrote:
P. Oscar Boykin, Ph.D. | http://twitter.com/posco | http://pobox.com/~boykin
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The entire picture isn't that clear to me either. It seems that a later version of simulacrum does use imp for summoning typeclasses instead of an
@inline def apply
method.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, the imp integration was just added in the last month or so. We could revert the imp integration to avoid the dependency and then tackle call-site inlining via macros ala imp and machinist once we start building typeclassic. I'm fine either way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 to no runtime deps, so reverting imp or using an older version would be my pref.