scalafmt reformat (#91)

* scalafmt config

* scalafmt reformat

* revert scaladoc to javadoc

* danglingParentheses = true

* delete scalariform prefs

* delete scalariform imports

* disabling test
This commit is contained in:
Dima 2018-03-20 14:58:08 +03:00 committed by GitHub
parent 250e4f1371
commit f0fa6a16e1
5 changed files with 41 additions and 29 deletions

View File

@ -51,7 +51,9 @@ object Codec {
implicit def identityCodec[F[_]: Applicative, T]: Codec[F, T, T] = implicit def identityCodec[F[_]: Applicative, T]: Codec[F, T, T] =
Codec(_.pure[F], _.pure[F]) Codec(_.pure[F], _.pure[F])
implicit def traverseCodec[F[_] : Applicative, G[_] : Traverse, O, B](implicit codec: Codec[F, O, B]): Codec[F, G[O], G[B]] = implicit def traverseCodec[F[_]: Applicative, G[_]: Traverse, O, B](
implicit codec: Codec[F, O, B]
): Codec[F, G[O], G[B]] =
Codec[F, G[O], G[B]](Traverse[G].traverse[F, O, B](_)(codec.encode), Traverse[G].traverse[F, B, O](_)(codec.decode)) Codec[F, G[O], G[B]](Traverse[G].traverse[F, O, B](_)(codec.encode), Traverse[G].traverse[F, B, O](_)(codec.decode))
implicit def toDirect[F[_], A, B](implicit cod: Codec[F, A, B]): Kleisli[F, A, B] = implicit def toDirect[F[_], A, B](implicit cod: Codec[F, A, B]): Kleisli[F, A, B] =
@ -70,10 +72,11 @@ object Codec {
implicit def byteVectorB64[F[_]](implicit F: ApplicativeError[F, Throwable]): Codec[F, String, ByteVector] = implicit def byteVectorB64[F[_]](implicit F: ApplicativeError[F, Throwable]): Codec[F, String, ByteVector] =
Codec( Codec(
str str
ByteVector.fromBase64(str).fold[F[ByteVector]]( ByteVector
.fromBase64(str)
.fold[F[ByteVector]](
F.raiseError(new IllegalArgumentException(s"Given string is not valid b64: $str")) F.raiseError(new IllegalArgumentException(s"Given string is not valid b64: $str"))
)(_.pure[F]), )(_.pure[F]),
_.toBase64.pure[F] _.toBase64.pure[F]
) )

View File

@ -43,7 +43,8 @@ class KryoCodecs[F[_], L <: HList] private (pool: KryoPool)(implicit F: MonadErr
*/ */
implicit def codec[T](implicit sel: ops.hlist.Selector[L, T]): Codec[F, T, Array[Byte]] = implicit def codec[T](implicit sel: ops.hlist.Selector[L, T]): Codec[F, T, Array[Byte]] =
Codec( Codec(
obj Option(obj) match { obj
Option(obj) match {
case Some(o) case Some(o)
F.catchNonFatal(Option(pool.toBytesWithClass(o))).flatMap { F.catchNonFatal(Option(pool.toBytesWithClass(o))).flatMap {
case Some(v) F.pure(v) case Some(v) F.pure(v)
@ -51,7 +52,9 @@ class KryoCodecs[F[_], L <: HList] private (pool: KryoPool)(implicit F: MonadErr
} }
case None case None
F.raiseError[Array[Byte]](new NullPointerException("Obj is null, encoding is impossible")) F.raiseError[Array[Byte]](new NullPointerException("Obj is null, encoding is impossible"))
}, binary F.catchNonFatal(pool.fromBytes(binary).asInstanceOf[T])) },
binary F.catchNonFatal(pool.fromBytes(binary).asInstanceOf[T])
)
} }
object KryoCodecs { object KryoCodecs {
@ -62,6 +65,7 @@ object KryoCodecs {
* @tparam L List of registered classes * @tparam L List of registered classes
*/ */
class Builder[L <: HList] private[KryoCodecs] (klasses: Seq[Class[_]]) { class Builder[L <: HList] private[KryoCodecs] (klasses: Seq[Class[_]]) {
/** /**
* Register a new case class T to Kryo * Register a new case class T to Kryo
* @tparam T Type to add * @tparam T Type to add
@ -70,7 +74,9 @@ object KryoCodecs {
* @param sa Presence of all types of S inside L * @param sa Presence of all types of S inside L
* @return Extended builder * @return Extended builder
*/ */
def addCase[T, S <: HList](klass: Class[T])(implicit gen: Generic.Aux[T, S], sa: ops.hlist.SelectAll[L, S]): Builder[T :: L] = def addCase[T, S <: HList](
klass: Class[T]
)(implicit gen: Generic.Aux[T, S], sa: ops.hlist.SelectAll[L, S]): Builder[T :: L] =
new Builder[T :: L](klasses :+ klass) new Builder[T :: L](klasses :+ klass)
/** /**
@ -88,7 +94,9 @@ object KryoCodecs {
* @tparam F Effect type * @tparam F Effect type
* @return Configured instance of KryoCodecs * @return Configured instance of KryoCodecs
*/ */
def build[F[_]](poolSize: Int = Runtime.getRuntime.availableProcessors)(implicit F: MonadError[F, Throwable]): KryoCodecs[F, L] = def build[F[_]](
poolSize: Int = Runtime.getRuntime.availableProcessors
)(implicit F: MonadError[F, Throwable]): KryoCodecs[F, L] =
new KryoCodecs[F, L]( new KryoCodecs[F, L](
KryoPool.withByteArrayOutputStream( KryoPool.withByteArrayOutputStream(
poolSize, poolSize,

View File

@ -26,7 +26,8 @@ import org.objenesis.strategy.StdInstantiatorStrategy
* @param classesToReg additional classes for registration * @param classesToReg additional classes for registration
* @param registrationRequired if true, an exception is thrown when an unregistered class is encountered. * @param registrationRequired if true, an exception is thrown when an unregistered class is encountered.
*/ */
private[kryo] case class KryoFactory(classesToReg: Seq[Class[_]], registrationRequired: Boolean) extends KryoInstantiator { private[kryo] case class KryoFactory(classesToReg: Seq[Class[_]], registrationRequired: Boolean)
extends KryoInstantiator {
override def newKryo(): KryoBase = { override def newKryo(): KryoBase = {
val kryo = new KryoBase() val kryo = new KryoBase()

View File

@ -30,7 +30,8 @@ class KryoCodecsSpec extends WordSpec with Matchers {
private val testCodecs = private val testCodecs =
KryoCodecs() KryoCodecs()
.add[Array[Array[Byte]]] .add[Array[Array[Byte]]]
.addCase(classOf[TestClass]).build[Try]() .addCase(classOf[TestClass])
.build[Try]()
"encode and decode" should { "encode and decode" should {
"be inverse functions" when { "be inverse functions" when {
@ -69,4 +70,3 @@ class KryoCodecsSpec extends WordSpec with Matchers {
} }
case class TestClass(str: String, num: Long, blob: Array[Array[Byte]]) case class TestClass(str: String, num: Long, blob: Array[Array[Byte]])