Skip to content

Commit

Permalink
Algebras Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefanos Stefanou committed Nov 8, 2023
1 parent cf92a88 commit e7211e9
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 9 deletions.
2 changes: 1 addition & 1 deletion diagram.drawio
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<mxfile host="Electron" modified="2023-11-02T11:32:30.414Z" agent="5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/18.0.0 Chrome/100.0.4896.143 Electron/18.2.0 Safari/537.36" etag="EoBjPJZ7Sm39j1Mcr1Nc" version="18.0.0" type="device" pages="2"><diagram id="tPDxc9v9lSpUtl4Dx5MV" name="Initial Big Picture">7V1bd5u4Fv4t58Gr6QNdXH15tJ2kt+RMp8mZNnmZJYNsqwFEhRzb8+uPBAJzkS+NMZhOHpKAJIT49kVbW3srHWPsrd4TEMxvsQPdjq46q45x2dF1bWAY7A8vWcclutrvxiUzghzRalNwh/6BolAVpQvkwDDXkGLsUhTkC23s+9CmuTJACF7mm02xm39rAGawVHBnA7dc+g05dB6X9vXepvwDRLN58matO4hrPJA0Fl8SzoGDl5ki46pjjAnGNL7yVmPocvQSXOLnrrfUpgMj0KeHPHD/+fO3h5/h3U/nm7oM8ejuunejCPI8A3chPlgMlq4TBAhe+A7knWgdY7ScIwrvAmDz2iUjOiubU88V1eVBiXE+Q0LhKlMkBvkeYg9SsmZNRK1iGVb8jOAZpSsQXG4IoA26otE8i74lWgJB9Vna+wYYdiGwkeP0eL/uPox7tmfDL+Rz8DSeDxeK1m8DUFZfipRaRko3T4WU1QagDPNQltL7FQB19/B18Th+/3Rlfn/o6pPHWzTvK9qgYqSm2KdCgWp6NcgZCe8I4CyrjJvRl/GXbp0Ktqol8QSwKfr5wdZrAWxFOR0cKqVmFepMilu/hBJ0mIEgbjGhczzDPnCvNqWjDY4qu9u0ucE4EOj9gJSuBXxgQXEeW7hC9Hvm+oF39c4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MaNsMF+bBXsAcT3eNNNVKK1LC7x6XTWyHr+tacRyKCzlUNH9Oq32PNSugazodj+lyrkWAl1cKSle6UxwIbVSiEK3nCaM84G0KnHMilQLYfu0EKUWbjQPOK0ypuhc6/VUlfao1sSGyoTvY5ExQmihNSnWBaE1Kv/4hl22DSgq9ct2JMP6kYqcKrnTTUwtMmE3vg+gea5aFwUTo2VdBzV+wca56XHoNri6YOL7D7EGVqzvaojDYLQkgjf4deJ0BlDjPihwChQ4AQpdihO0OH2jBald5hoVCN8bq5HFaiGIcA5qBN8bqNACNac5SzWYEvP9t4qp3f9x626PHoAkpBEZWXupronAEiJ0kX/vyDloZIF+wmmOz4o2SRIQx6fQErRE4ZnQoqDPFgLXbMdvm/j6rQudWzeyrSsKobtcv3dD3zXciQX3c7HRuy7WawT+F6wThevDPDwQuPdwE/cO54d1ESu9+qulPBoNPnLON+LAztv6xwl+dtJRTE+TXkbhKDxT0jQk/Q78bGdNt2XJdx/HzaF7N9sZV82YxVixDf04pJF70na+1iF9L+VH2qbH7nHbWd8L5oxgpUEC/5andCnxRbZrJ8Qj98Tt9G+K41cu3F/eDI/El7yT0I/txfK+rnM9D+//AA==</diagram></mxfile>
<mxfile host="Electron" modified="2023-11-08T11:29:28.871Z" agent="5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/18.0.0 Chrome/100.0.4896.143 Electron/18.2.0 Safari/537.36" etag="EC0f2gJR-OAFu-owCELl" version="18.0.0" type="device" pages="2"><diagram id="tPDxc9v9lSpUtl4Dx5MV" name="Initial Big Picture">7V1bd5u4Fv4t58Gr6QNdXH15tJ2kt+RMp8mZNnmZJYNsqwFEhRzb8+uPBAJzkbEbY2M66VpNQBJCfPuira29lY4x9lbvCQjmt9iBbkdXnVXHuOzo7J9lsF+8ZC1KVLMbl8wIcuIybVNwh/6BolAVpQvkwDDXkGLsUhTkC23s+9CmuTJACF7mm02xm39rAGawVHBnA7dc+g05dB6X9vXepvw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ln9nJC8pHlhzjithyJsa2z0RePdd2TGPEvKxu8ff1PX+DXEu/wA=</diagram></mxfile>

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/main/scala/mycats/instances/ValidatedInstances.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import mycats.lib.obj.Semigroup

object ValidatedInstances {

implicit def validatedApplicativeErrorInstance[E](implicit semigroupOfE:Semigroup[E])=
implicit def validatedApplicativeErrorInstance[E](implicit semigroupOfE:Semigroup[E]): ApplicativeError[({
type Valid[C] = Validated[E, C]})#Valid, E] with BiFunctor[Validated]=
new ApplicativeError[({type Valid[C] = Validated[E, C]})#Valid,E] with BiFunctor[Validated]{
override def raiseError[A](e: E): Validated[E, A] = Invalid(e)
override def handleErrorWith[A](fa: Validated[E, A])(f: E => Validated[E, A]): Validated[E, A] = fa match {
Expand All @@ -24,7 +25,6 @@ object ValidatedInstances {
case Valid(valid) => Valid(f(valid))
case p@Invalid(invalid)=>p
}
//YEEEEEEE!
override def ap[A, B](ff: Validated[E, A => B])(fa: Validated[E, A]): Validated[E, B] = (ff,fa) match {
case (Valid(f),Valid(a))=>Valid(f(a))
case (Invalid(err1),Invalid(err2))=>Invalid(semigroupOfE.combine(err1,err2))
Expand Down
3 changes: 2 additions & 1 deletion src/main/scala/mycats/instances/ValidatedNelInstances.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import mycats.lib.obj.Semigroup

object ValidatedNelInstances {
implicit def semigroupOfNonEmptyList[A]:Semigroup[NonEmptyList[A]] = (x: NonEmptyList[A], y: NonEmptyList[A]) => x.appendedAll(y)
implicit val validatedNelInstance: ApplicativeError[({type Valid[C] = Validated[NonEmptyList[String], C]})#Valid, NonEmptyList[String]] with BiFunctor[Validated] = validatedApplicativeErrorInstance[NonEmptyList[String]]
implicit val validatedNelInstance: ApplicativeError[({type Valid[C] = Validated[NonEmptyList[String], C]})#Valid, NonEmptyList[String]] with BiFunctor[Validated] =
validatedApplicativeErrorInstance[NonEmptyList[String]]

}
9 changes: 9 additions & 0 deletions src/main/scala/mycats/lib/syntax/ApplicativeErrorSyntax.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package mycats.lib.syntax
import mycats.lib.morphisms.error.ApplicativeError

object ApplicativeErrorSyntax {
implicit class ApplicativeErrorSyntaxOps[F[_],A](fa:F[A]){
def handleErrorWith[E](handle:E=>F[A])(implicit ae:ApplicativeError[F,E]):F[A]=ae.handleErrorWith(fa)(handle)
def handleError[E](handle:E=>A)(implicit ae:ApplicativeError[F,E]):F[A]=ae.handleError(fa)(handle)
}
}
24 changes: 20 additions & 4 deletions src/test/scala/mycats/instances/ValidatedInstancesSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,37 @@ import mycats.lib.syntax.ApplySyntax.Tuple2ApplyOps
import mycats.instances.ValidatedNelInstances._
import mycats.lib.syntax.BiFunctorSyntax.BiFunctorSyntaxOps
import mycats.lib.syntax.SemigroupSyntax._
import mycats.lib.syntax.ApplicativeErrorSyntax._
import mycats.instances.ValidatedNelInstances.validatedNelInstance
class ValidatedNelInstancesSpec extends org.scalatest.funsuite.AnyFunSuite {
test("Semigroup NonEmptyList: combine should behave as expected") {
val nonEmpty1:NonEmptyList[Int] = 1::2::3::Nil
val nonEmpty2:NonEmptyList[Int] = 4::5::6::Nil
assert(nonEmpty1.combine(nonEmpty2)==(1 to 6).toList,"Semigroupal's .product does not return F[(A,B)] when applied in Option Algebra")
assert(nonEmpty1.combine(nonEmpty2)==(1 to 6).toList,"Semigroup NonEmptyList: combine does not concat the list as expected")
}
test("ValidatedNel BiFunctor: bimap should transform valid context") {
val validatedNel:ValidatedNel[Int] = Valid(42)
assert(validatedNel.bimap(_.headOption)(String.valueOf)==Valid("42"),"Semigroupal's .product does not return F[(A,B)] when applied in Option Algebra")
assert(validatedNel.bimap(_.headOption)(String.valueOf)==Valid("42"),"ValidatedNel BiFunctor: bimap does not transform Valid Context properly")
}
test("ValidatedNel BiFunctor: bimap should transform invalid context") {
val validatedNel:ValidatedNel[Int] = Invalid("Error"::Nil)
assert(validatedNel.bimap(_.head)(String.valueOf)==Invalid("Error"),"Semigroupal's .product does not return F[(A,B)] when applied in Option Algebra")
assert(validatedNel.bimap(_.head)(String.valueOf)==Invalid("Error"),"ValidatedNel BiFunctor: bimap does not transform Invalid Context properly")
}
test("ValidatedNel ApplicativeError: raiseError should lift E to Validated[E,A] as invalid projection") {
assert(validatedNelInstance.raiseError(List("Some Error"))==Invalid(List("Some Error")),"ValidatedNel ApplicativeError: raiseError does not lift E to Validated[E,A] as invalid projection")
}
test("ValidatedNel ApplicativeError: handleError should behave as identity map when acted upon a valid instance") {
val validatedNel:ValidatedNel[Int] = Valid(42)
val identity:ValidatedNel[Int] = validatedNel.handleError[NonEmptyList[String]](_=>40)
assert(identity==validatedNel,"ValidatedNel ApplicativeError: handleError alters a Valid Instance")
}
//BiFunctor (bimap)
test("ValidatedNel ApplicativeError: handleError should recover an invalid operation") {
val invalidNel:ValidatedNel[Int] = Invalid(List("ExistentialCrisisErr: Unable to find meaning of life"))
val recover:ValidatedNel[Int] = invalidNel.handleError[NonEmptyList[String]](_=>42)
assert(recover==Valid(42),"ValidatedNel ApplicativeError: handleError does not recover failed operation")
}


//ApplicativeError (raiseError,handleErrorWith,handleError)
//Applicative (pure)
//Apply (ap)
Expand Down
1 change: 1 addition & 0 deletions ~$diagram.drawio.bkp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<mxfile host="Electron" modified="2023-11-02T11:32:30.414Z" agent="5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/18.0.0 Chrome/100.0.4896.143 Electron/18.2.0 Safari/537.36" etag="EoBjPJZ7Sm39j1Mcr1Nc" version="18.0.0" type="device" pages="2"><diagram id="tPDxc9v9lSpUtl4Dx5MV" name="Initial Big Picture">7V1bd5u4Fv4t58Gr6QNdXH15tJ2kt+RMp8mZNnmZJYNsqwF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u9+qulPBoNPnLON+LAztv6xwl+dtJRTE+TXkbhKDxT0jQk/Q78bGdNt2XJdx/HzaF7N9sZV82YxVixDf04pJF70na+1iF9L+VH2qbH7nHbWd8L5oxgpUEC/5andCnxRbZrJ8Qj98Tt9G+K41cu3F/eDI/El7yT0I/txfK+rnM9D+//AA==</diagram></mxfile>

0 comments on commit e7211e9

Please sign in to comment.