Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Nov 27 16:43

    joroKr21 on main

    Update slf4j-nop to 2.0.5 (#129… (compare)

  • Nov 27 16:43
    joroKr21 closed #1293
  • Nov 26 17:38
    scala-steward opened #1293
  • Nov 24 22:35

    joroKr21 on main

    Update sbt-scalajs, scalajs-com… (compare)

  • Nov 24 22:35
    joroKr21 closed #1291
  • Nov 24 22:14
    joroKr21 synchronize #1291
  • Nov 24 22:13
    joroKr21 closed #1288
  • Nov 24 22:13

    joroKr21 on main

    Update junit-plugin, junit-runt… (compare)

  • Nov 24 22:13
    joroKr21 closed #1292
  • Nov 24 18:03
    scala-steward commented #1288
  • Nov 24 18:03
    scala-steward opened #1292
  • Nov 24 18:03
    scala-steward opened #1291
  • Nov 19 21:17

    joroKr21 on main

    Update slf4j-nop to 2.0.4 (#129… (compare)

  • Nov 19 21:17
    joroKr21 closed #1290
  • Nov 18 20:54
    scala-steward opened #1290
  • Nov 15 06:50
    joroKr21 commented #1286
  • Nov 15 06:48
    joroKr21 commented #1287
  • Nov 15 06:41
    joroKr21 synchronize #1288
  • Nov 15 06:41

    joroKr21 on main

    Update sbt to 1.8.0 (#1289) (compare)

  • Nov 15 06:41
    joroKr21 closed #1289
David Hoyt
@davidhoyt
generally speaking, I want to take nested case classes and spit out a flattened list of field=value. e.g.:
case class Foo(a: String, b: Bar)
case class Bar(c: Int, d: Baz)
case class Baz(e: Long)

val instance = Foo("A", Bar(1, Baz(2)))

val flattened: String = ??? // Should be "a=A c=1 e=2"
I've started by looking at LabelledGeneric and can iterate over fields and values, but I haven't thus far worked out how to successfully determine if I'm nested
Andrew Roberts
@aroberts
(operates on tuples but hlist is isomorphic to tuple)
Fabio Labella
@SystemFw
@davidhoyt the problem with what you want to do
is not flattening, that's easy
actually, I take it back. Flattening HLists is easy
flattening Products has additional difficulties, let me give it a try
Andrew Roberts
@aroberts
@SystemFw I think I took the same approach, just organized a little bit differently
Fabio Labella
@SystemFw
:+1:
Andrew Roberts
@aroberts
the only think I’m missing is deriving the freaking cases from within the coproduct derived codec
Fabio Labella
@SystemFw
what I like about OptIn is that I can envision it being expanded with options to customise the derivation, using the same scheme
@aroberts how are you encoding the coproduct?
I mean the mapping Coproduct => Index
what is it?
Andrew Roberts
@aroberts
I created a special-case encoding instance that’s index-aware
Fabio Labella
@SystemFw
yeah that's not what I mean
Andrew Roberts
@aroberts
trait MsgpackIndexed[A] extends Msgpack[A] {
  private val si = Serialize[Int]
  val defaultIndex = 0

  def pack(v: A) = packIndexed(defaultIndex, v).flatMap((packWithIndex _).tupled)
  def unpack(v: MessagePack) = v match {
    case MFixArray(Vector(i, m)) => si.unpack(i).flatMap(unpackIndexed(_, m))
    case _ => Attempt.failure(Err(s"Couldn't unpack indexed messagepack from $v"))
  }

  def packIndexed(index: Int, v: A): Attempt[(Int, MessagePack)]
  def unpackIndexed(index: Int, v:  MessagePack): Attempt[A]

  private def packWithIndex(index: Int, payload: MessagePack): Attempt[MessagePack] =
    si.pack(index).map(packed => MFixArray(Vector(packed, payload)))
}
Fabio Labella
@SystemFw
ah ok wait
nope, that's not what I mean :)
but rather, given an ADT coproduct, how does the numbering work?
Andrew Roberts
@aroberts
This message was deleted
Fabio Labella
@SystemFw
e.g. the first case gets 0, and so on
Andrew Roberts
@aroberts
  implicit val serializeCNil: MsgpackIndexed[CNil] = new MsgpackIndexed[CNil] {
    def packIndexed(index: Int, v: CNil) = Attempt.failure(Err(s"CNil can't be packed: $v"))
    def unpackIndexed(index: Int, v: MessagePack) = Attempt.failure(Err(s"CNil can't be unpacked: $v"))
  }

  implicit def serializeCCons[H, T <: Coproduct](implicit
      hSer: Msgpack[H],
      tSer: MsgpackIndexed[T]
  ): MsgpackIndexed[H :+: T] = new MsgpackIndexed[H :+: T] {
    def packIndexed(index: Int, v: H :+: T) = v match {
      case Inl(h) => hSer.pack(h).map((index, _))
      case Inr(t) => tSer.packIndexed(index + 1, t)
    }

    def unpackIndexed(index: Int, v: MessagePack) = index match {
      case 0 => hSer.unpack(v).map(Inl(_))
      case n => tSer.unpackIndexed(n - 1, v).map(Inr(_))
    }
  }
Is that what you mean? it’s basically a count of how many Inr cases are processed before an Inl instance is encountered
Fabio Labella
@SystemFw
yes
what's the problem with it?
Andrew Roberts
@aroberts
nothing, as far as I can tell
Fabio Labella
@SystemFw
ah
Andrew Roberts
@aroberts
the issue is a derivation problem
auto derivation after invocation
Fabio Labella
@SystemFw
I don't follow
(sorry, I thought you were still stuck on the above, but the approach I was going to suggest is what you already have :) )
mm actually wait
Andrew Roberts
@aroberts
 it should "derive Msgpack instances for sealed ADTs" in {
    implicit val childSer: Msgpack[Family.Child] = deriveMsgpack
    implicit val parentSer: Msgpack[Family.Parent] = deriveMsgpack

    implicit val ser: Msgpack[Family] = deriveMsgpack
}
this block doesn’t compile when I comment out the first two implicits
but with them in place, it compiles just fine
Fabio Labella
@SystemFw
do you have Coproduct instances for MagPack?
Andrew Roberts
@aroberts
yeah, pasted above
serializeCNil and serializeCCons
Fabio Labella
@SystemFw
those are MsgPackIndexed, not MsgPack
Andrew Roberts
@aroberts
that spec says to me that when I’m constructing a DerivedMsgpack instance for Family, the derive code isn’t able to reach into the Repr of Family and derive missing Msgpack instances
MsgpackIndexed <: Msgpack
Fabio Labella
@SystemFw
welcome to the beautiful world of mixing implicits and sub typing :)
Andrew Roberts
@aroberts
also, the spec I pasted above wouldn’t compile if I didn’t have coproduct implicits
so I’m confident those are getting found
I think it’s an implicit resolution problem
hah- yeah pretty awesome...
Fabio Labella
@SystemFw
can you the[MsgPack[Int :+: CNil]]
Andrew Roberts
@aroberts
let’s see...
yep