github-actions[bot] on gh-pages
deploy: 2969f82e29d1b5fcddbedff… (compare)
armanbilge on custom-update-flake-branch
rossabaker on 0.23
[ci skip] Custom branch for upd… Merge pull request #6498 from h… (compare)
github-actions[bot] on gh-pages
deploy: a64f93143565a52fdb7667c… (compare)
armanbilge on git-blame-ignore-revs
rossabaker on 0.23
[ci skip] Create `.git-blame-ig… [ci skip] add another fmt commit [ci skip] fix wrong comment and 1 more (compare)
armanbilge on git-blame-ignore-revs
[ci skip] fix wrong comment (compare)
armanbilge on git-blame-ignore-revs
[ci skip] add another fmt commit (compare)
withLog
would be sufficient for this use case.
logMe[IO]("hello")
will think that "hello" is Sync[F]
apply
, but it's more horrendous in implementation
def logMe[F[_]]: Magnet[F] = new Magnet[F]
class Magnet[F[_]]
object Magnet {
implicit def conv[F[_]: Sync](m: Magnet[F]): LogMePartiallyApplied[F] =
new LogMePartiallyApplied[F]
class LogMePartiallyApplied[F[_]: Sync] {
def apply(s: String, logAction: String => F[Unit] = { s =>
Sync[F].delay(println(s))
}) =
logAction(s)
}
}
def yolo = logMe[IO]("hello")
// scala> yolo.unsafeRunSync
// hello
234sekjfasdf
or it didn’t happen.
implicitNotFound
does not work (if it fails the implicit search you simply do not trigger the conversion)
def yolo = logMe[IO]("hello")
// scala> yolo.unsafeRunSync
// hello
def well = logMe("hello")
Users/fabio/projects/playground/src/main/scala/Playground.scala:57: Specify `IO` there: `logMe[IO]("hello")`
[error] def well = logMe("hello")
def logMe[F[_]]: Magnet[F] = new Magnet[F]
class Magnet[F[_]]
trait LowPrio {
@annotation.implicitNotFound("""Specify `IO` there: `logMe[IO]("hello")`""")
trait Error
class Catch[F[_]] {
def apply(s: String, logAction: String => F[Unit] = ???)(implicit ev: Error) =
???
}
implicit def conv2[F[_]](m: Magnet[F]): Catch[F] =
new Catch[F]
}
object Magnet extends LowPrio {
implicit def conv[F[_]: Sync](m: Magnet[F]): LogMePartiallyApplied[F] =
new LogMePartiallyApplied[F]
class LogMePartiallyApplied[F[_]: Sync] {
def apply(s: String, logAction: String => F[Unit] = { s =>
Sync[F].delay(println(s))
}) =
logAction(s)
}
}
enjoy