Skip to content

Commit

Permalink
refactor(syntax): more abstraction, use HKT instead of IO
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshinorin committed Dec 3, 2023
1 parent 7a6cb89 commit 4f5edc7
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 deletions.
17 changes: 0 additions & 17 deletions src/main/scala/net/yoshinorin/qualtet/syntax/io.scala

This file was deleted.

18 changes: 18 additions & 0 deletions src/main/scala/net/yoshinorin/qualtet/syntax/monad.scala
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)
}
}
}

}
2 changes: 1 addition & 1 deletion src/main/scala/net/yoshinorin/qualtet/syntax/syntax.scala
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ trait throwable {
IO(e)
}
}

}

0 comments on commit 4f5edc7

Please sign in to comment.