1 Commits

Author SHA1 Message Date
cf36fdb00e A couple of shortcut methods on Func 2019-08-14 16:33:25 +03:00
4 changed files with 81 additions and 50 deletions

View File

@ -1,5 +1,6 @@
import de.heikoseeberger.sbtheader.License import de.heikoseeberger.sbtheader.License
import sbtcrossproject.crossProject import org.scalajs.sbtplugin.ScalaJSPlugin.autoImport._
import sbtcrossproject.CrossPlugin.autoImport.crossProject
name := "codec" name := "codec"
@ -13,7 +14,7 @@ val scalaV = scalaVersion := "2.12.8"
val commons = Seq( val commons = Seq(
scalaV, scalaV,
crossScalaVersions := Seq(scalaVersion.value, "2.13.0"), //crossScalaVersions := Seq(scalaVersion.value, "2.13.0-RC1"),
version := "0.0.5", version := "0.0.5",
fork in Test := true, fork in Test := true,
parallelExecution in Test := false, parallelExecution in Test := false,
@ -30,18 +31,19 @@ val commons = Seq(
commons commons
val kindProjector = addCompilerPlugin("org.typelevel" % "kind-projector" % "0.10.3" cross CrossVersion.binary) val kindProjector = addCompilerPlugin("org.typelevel" % "kind-projector" % "0.10.0" cross CrossVersion.binary)
val Cats1V = "2.0.0-RC1" val Cats1V = "1.6.0"
val ScodecBitsV = "1.1.10" val ScodecBitsV = "1.1.10"
val CirceV = "0.12.0-RC2" val CirceV = "0.11.1"
val ShapelessV = "2.3.+" val ShapelessV = "2.3.+"
val chill = "com.twitter" %% "chill" % "0.9.3" val chill = "com.twitter" %% "chill" % "0.9.3"
val ScalatestV = "3.0.5" val ScalatestV = "3.0.5"
val ScalacheckV = "1.14.0" // Note that cats-laws 1.5 are compiled against scalacheck 1.13, and scalacheck-shapeless should also not introduce the upgrade
val ScalacheckV = "1.13.5"
val protobuf = Seq( val protobuf = Seq(
PB.targets in Compile := Seq( PB.targets in Compile := Seq(
@ -64,7 +66,7 @@ lazy val `codec-core` = crossProject(JVMPlatform, JSPlatform)
libraryDependencies ++= Seq( libraryDependencies ++= Seq(
"org.typelevel" %%% "cats-core" % Cats1V, "org.typelevel" %%% "cats-core" % Cats1V,
"org.typelevel" %%% "cats-testkit" % Cats1V % Test, "org.typelevel" %%% "cats-testkit" % Cats1V % Test,
"com.github.alexarchambault" %%% "scalacheck-shapeless_1.13" % "1.2.3" % Test, "com.github.alexarchambault" %%% "scalacheck-shapeless_1.13" % "1.1.8" % Test,
"org.scalacheck" %%% "scalacheck" % ScalacheckV % Test, "org.scalacheck" %%% "scalacheck" % ScalacheckV % Test,
"org.scalatest" %%% "scalatest" % ScalatestV % Test "org.scalatest" %%% "scalatest" % ScalatestV % Test
) )

View File

@ -49,6 +49,7 @@ abstract class MonadicalEitherArrow[E <: Throwable] {
* @tparam B Successful result type * @tparam B Successful result type
*/ */
abstract class Func[A, B] { abstract class Func[A, B] {
f
/** /**
* Run the func on input, using the given monad. * Run the func on input, using the given monad.
@ -76,6 +77,30 @@ abstract class MonadicalEitherArrow[E <: Throwable] {
*/ */
def apply[F[_]: Monad](input: A): EitherT[F, E, B] def apply[F[_]: Monad](input: A): EitherT[F, E, B]
/**
* Shortcut for function composition
*
* @param other Other function to run after
* @tparam C Resulting input type
* @return Composed function
*/
def on[C](other: Func[C, A]): Func[C, B] =
catsMonadicalEitherArrowChoice.compose(this, other)
/**
* Convert this Func into another one, lifting the error
*
* @param m Another instance of MonadicalEitherArrow
* @param convertE Convert error
* @tparam EE Error type
* @return Converted function
*/
def to[EE <: Throwable](m: MonadicalEitherArrow[EE])(implicit convertE: E EE): m.Func[A, B] =
new m.Func[A, B] {
override def apply[F[_]: Monad](input: A): EitherT[F, EE, B] =
f[F](input).leftMap(convertE)
}
/** /**
* Converts this Func to Kleisli, using MonadError to execute upon and to lift errors into. * Converts this Func to Kleisli, using MonadError to execute upon and to lift errors into.
* *

View File

@ -101,6 +101,8 @@ object KryoCodecs {
/** /**
* Build a new instance of KryoCodecs with the given poolSize and F effect * Build a new instance of KryoCodecs with the given poolSize and F effect
* @param poolSize Kryo pool size * @param poolSize Kryo pool size
* @param F ApplicativeError for catching serialization errors
* @tparam F Effect type
* @return Configured instance of KryoCodecs * @return Configured instance of KryoCodecs
*/ */
def build( def build(

View File

@ -1,19 +1,21 @@
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.0.3") addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.0.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.3.25") addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.3.20")
addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.2.0") addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.2.0")
addSbtPlugin("com.thesamet" % "sbt-protoc" % "0.99.23") addSbtPlugin("com.thesamet" % "sbt-protoc" % "0.99.20")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.28") addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.27")
addSbtPlugin("org.portable-scala" % "sbt-crossproject" % "0.6.1") addSbtPlugin("org.portable-scala" % "sbt-crossproject" % "0.6.0")
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "0.6.1") addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "0.6.0")
addSbtPlugin("ch.epfl.scala" % "sbt-scalajs-bundler" % "0.15.0") addSbtPlugin("ch.epfl.scala" % "sbt-scalajs-bundler" % "0.14.0")
addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.9.2") addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.9.2")
libraryDependencies += "com.thesamet.scalapb" %% "compilerplugin" % "0.9.0" addSbtPlugin("com.lihaoyi" % "workbench" % "0.4.1")
libraryDependencies += "com.thesamet.scalapb" %% "compilerplugin" % "0.8.4"
addSbtPlugin("org.foundweekends" % "sbt-bintray" % "0.5.4") addSbtPlugin("org.foundweekends" % "sbt-bintray" % "0.5.4")