scala-2.12

Deriving a Cats Order for Scala's Enumeration

那年仲夏 提交于 2019-12-10 23:46:06
问题 I would like a generic Cats Order for Scala's Enumeration . I tried implicit def enumOrder[E <: Enumeration, V <: E#Value]: cats.Order[V] = new cats.Order[V] { def compare(x: V, y: V): Int = x.compare(y) } but I get [error] overloaded method value compare with alternatives: [error] ((that: _1.Value)Int) forSome { val _1: E } <and> [error] (that: _1.Value)Int [error] cannot be applied to (V) [error] def compare(x: V, y: V): Int = x.compare(y) [error] ^ Does anybody know how I can implement

Scala hex literal for bytes

蓝咒 提交于 2019-12-06 04:05:50
Hex literal containing A-F digit are converting to int by default. When I am trying to declear an Int with 0x it is creating correctly. val a: Int = 0x34 val b: Int = 0xFF But when I am trying to declear a Byte with 0x second line is not compiling val a: Byte = 0x34 val b: Byte = 0xFF // compilation error I have found a workaround that is val a: Byte = 0x34 val b: Byte = 0xFF.toByte But is there any decent way to declear a Byte from its hex literal? For example I am trying to declear a Byte array in a Test method in this way anObject.someMethod(1, 1.1f, 0xAB, "1") shouldBe Array[Byte](0xAF,