Skip to content

Commit

Permalink
Merge pull request #93 from FunFunFine/patch-1
Browse files Browse the repository at this point in the history
Solution to issue #92
  • Loading branch information
Z1kkurat authored Dec 27, 2019
2 parents 2c25168 + 3ed5c23 commit 20a5384
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions higherKindCore/src/main/scala/tofu/syntax/monadic.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,20 @@ object monadic extends TupleSemigroupalSyntax with ApplicativeSyntax with MonadS
def tupleRight[B](b: B)(implicit F: Functor[F]): F[(A, B)] = F.tupleRight(fa, b)
}

implicit class TofuSemigroupalOps[F[_], A](private val fa: F[A]) extends AnyVal{
implicit class TofuSemigroupalOps[F[_], A](private val fa: F[A]) extends AnyVal {
def product[B](fb: F[B])(implicit F: Semigroupal[F]): F[(A, B)] = F.product(fa, fb)
}

implicit final class TofuApplyFuncOps[F[_], A, B](private val fab: F[A => B]) extends AnyVal {
def ap(fa: F[A])(implicit F: Apply[F]): F[B] = F.ap(fab)(fa)
def <*>(fa: F[A])(implicit F: Apply[F]): F[B] = F.ap(fab)(fa)
}


implicit class TofuApplicativeOps[F[_], A](private val condition: Boolean) extends AnyVal {
def whenOpt(fa: =>F[A])(implicit F: Applicative[F]): F[Option[A]] = if (condition) F.map(fa)(Some(_)) else F.pure(None)
def unlessOpt(fa: =>F[A])(implicit F: Applicative[F]): F[Option[A]] = if (condition) F.pure(None) else F.map(fa)(Some(_))
}

implicit final class TofuApplyFunc2Ops[F[_], A, B, C](private val fab: F[(A, B) => C]) extends AnyVal {
def ap2(fa: F[A], fb: F[B])(implicit F: Apply[F]): F[C] = F.ap2(fab)(fa, fb)
}
Expand Down

0 comments on commit 20a5384

Please sign in to comment.