-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #100 from TinkoffCreditSystems/minor_fixes
Add summon to Execute, add putErr and putErrLn to Console, scalafmt f…
- Loading branch information
Showing
8 changed files
with
51 additions
and
39 deletions.
There are no files selected for viewing
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
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
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
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,27 +1,45 @@ | ||
package tofu.common | ||
|
||
import java.io.{BufferedReader, PrintStream} | ||
|
||
import scala.{Console => ScalaConsole} | ||
|
||
import cats.effect.Sync | ||
import simulacrum.typeclass | ||
import tofu.higherKind | ||
import tofu.higherKind.RepresentableK | ||
|
||
import scala.io.StdIn | ||
|
||
@typeclass | ||
trait Console[F[_]] { | ||
def readStrLn: F[String] | ||
|
||
def putStr(s: String): F[Unit] | ||
def putStrLn(s: String): F[Unit] | ||
|
||
def readStrLn: F[String] | ||
def putErr(err: String): F[Unit] | ||
def putErrLn(err: String): F[Unit] | ||
} | ||
|
||
object Console { | ||
def putStr[F[_]](s: String)(implicit C: Console[F]): F[Unit] = C.putStr(s) | ||
def putStrLn[F[_]](s: String)(implicit C: Console[F]): F[Unit] = C.putStrLn(s) | ||
def readStrLn[F[_]](implicit C: Console[F]): F[String] = C.readStrLn | ||
def readStrLn[F[_]: Console]: F[String] = Console[F].readStrLn | ||
|
||
def putStr[F[_]: Console](s: String): F[Unit] = Console[F].putStr(s) | ||
def putStrLn[F[_]: Console](s: String): F[Unit] = Console[F].putStrLn(s) | ||
|
||
def putErr[F[_]: Console](e: String): F[Unit] = Console[F].putErr(e) | ||
def putErrLn[F[_]: Console](e: String): F[Unit] = Console[F].putErrLn(e) | ||
|
||
implicit val representableKInstance: RepresentableK[Console] = higherKind.derived.genRepresentableK[Console] | ||
|
||
implicit def syncInstance[F[_]](implicit F: Sync[F]): Console[F] = new Console[F] { | ||
def putStr(s: String): F[Unit] = F.delay(print(s)) | ||
def putStrLn(s: String): F[Unit] = F.delay(println(s)) | ||
def readStrLn: F[String] = F.delay(StdIn.readLine()) | ||
implicit def syncInstance[F[_]: Sync]: Console[F] = instance(ScalaConsole.in, ScalaConsole.out, ScalaConsole.err) | ||
|
||
def instance[F[_]: Sync](in: BufferedReader, out: PrintStream, err: PrintStream): Console[F] = new Console[F] { | ||
def readStrLn: F[String] = Sync[F].delay(in.readLine()) | ||
|
||
def putStr(s: String): F[Unit] = Sync[F].delay(out.print(s)) | ||
def putStrLn(s: String): F[Unit] = Sync[F].delay(out.println(s)) | ||
|
||
def putErr(e: String): F[Unit] = Sync[F].delay(err.print(e)) | ||
def putErrLn(e: String): F[Unit] = Sync[F].delay(err.println(e)) | ||
} | ||
} |
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
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
4 changes: 0 additions & 4 deletions
4
logging/structured/src/main/scala-2.12/tofu/logging/LogsVOps.scala
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,7 +1,3 @@ | ||
package tofu.logging | ||
import cats.Functor | ||
import tofu.syntax.monadic._ | ||
|
||
import scala.reflect.ClassTag | ||
|
||
trait LogsVOps[I[_], F[_]] |
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