-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(syntax): more abstraction, use
HKT
instead of IO
- Loading branch information
1 parent
7a6cb89
commit 4f5edc7
Showing
4 changed files
with
20 additions
and
18 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,18 @@ | ||
package net.yoshinorin.qualtet.syntax | ||
|
||
import cats.{Monad, MonadError} | ||
import scala.reflect.ClassTag | ||
import cats.syntax.flatMap.toFlatMapOps | ||
|
||
trait monad { | ||
|
||
extension [F[_]: Monad, A: ClassTag](monad: F[Option[A]]) { | ||
def throwIfNone[T <: Throwable](t: T)(implicit me: MonadError[F, Throwable]): F[A] = { | ||
monad.flatMap { | ||
case Some(a: A) => Monad[F].pure(a) | ||
case _ => MonadError[F, Throwable].raiseError(t) | ||
} | ||
} | ||
} | ||
|
||
} |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
package net.yoshinorin.qualtet | ||
|
||
package object syntax extends string with eitherT with tuple with validator with io with option with json with http with throwable with points | ||
package object syntax extends string with eitherT with tuple with validator with monad with option with json with http with throwable with points |
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 |
---|---|---|
|
@@ -19,4 +19,5 @@ trait throwable { | |
IO(e) | ||
} | ||
} | ||
|
||
} |