by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Steven Fines
@sfines-clgx
yeah, so state gets composed into a Key, and one of the elements of a key is a constant string defining what type of key it is
sealed trait RedisKey { val indexCode: String val indexLevel: IndexLevel val keyValue: String val keyDate: DateTime }
si
that's the Type definition, but the concrete class looks like:
case class HpiKey(
                   override val indexLevel: IndexLevel,
                   override val keyValue: String,
                   override val keyDate: DateTime,
                 ) extends RedisKey {
  override val indexCode: String = "HPI"
}
a
the final would looking something like "HPI:state:06:202009"
but what I am curently getting is "state:06:202009"
so it looks like the Generic is not getting the non-arglist field
Ethan
@esuntag
Ah yeah, you'll need indexCode in the parameter list if you want shapeless to be aware of it
Steven Fines
@sfines-clgx
that was what I thought. Is there a better way to do this if I want to use the type to determine that string and not have it in the arglist?
Ethan
@esuntag
You could write a custom Encoder[RedisKey] that uses the derived encoder, and then tacks on the indexCode
Steven Fines
@sfines-clgx
something like ```
Ethan
@esuntag
You can shift+enter for newline without sending
Steven Fines
@sfines-clgx
  implicit def rkEncoder[RedisKey](value:RedisKey)(implicit rEnc:Encoder[RedisKey]) = createEncoder{
    List(value.indexCode) ++ rEnc.encode(value) 
  }
yeah, I just hit the keys out of order ;)
Steven Fines
@sfines-clgx
I could also do what I want with records, it seems
Steven Fines
@sfines-clgx
Ok, I found an acceptable solution, rather than use Generic to build the HList, I manually make it
it's not perfect, but is ok for now while I learn more
@esuntag thank you for all of your help
Ethan
@esuntag
That won't quite work, since the implicit Encoder[RedisKey] it'll find is the one you're trying to create
Also, the typeclass instances can't take values
implicit def redisEncoder[R](
    implicit
    gen: Generic.Aux[RedisKey,R],
    enc: Encoder[R]
  ): Encoder[RedisKey] = createEncoder(key => key.indexCode :: enc.encode(gen.to(key)))
What records give you is access to the field name as well as the value, I think the type astronaut book covers them later on
Steven Fines
@sfines-clgx
cooooooooool
that works much more like I would like it to
Steven Fines
@sfines-clgx
are HMaps a good replacement for Dynamic classes?
Ethan
@esuntag
I'd be more inclined to build a custom Record there. Although it's honestly not something I've needed.
Markus Appel
@markusa380
I have two record types, A and B. A contains all fields from B.
How can I map an A into a B?
Paul Snively
@paul-snively
Sounds like Union maybe?
Paul Snively
@paul-snively
Merger?
Ben Spencer
@dangerousben
can anyone recommend somewhere to read up on the current state of shapeless' optics? covering Path, for example
Christopher Davenport
@ChristopherDavenport
@milessabin Is there a reason shapless 3 doesnt have Nat/Witness stuff in it? Is it not necessary in dotty?
Fabio Labella
@SystemFw
@ChristopherDavenport literal types?
Ethan
@esuntag
Can you do something like Succ[N] with literal types in dotty?
Christopher Davenport
@ChristopherDavenport
Yeah. That'll definitely take care of witness.
Trying to imagine how to do logic I had on Sized matches with shapeless 2.
Dan Di Spaltro
@dispalt
I recently tried to update a repo which uses shapeless to 2.13, and I am getting this error which I don't understand
[error]  found   : T :: T :: T :: T :: T :: T :: T :: T :: T :: T :: shapeless.HNil
[error]  required: T :: T :: T :: T :: T :: T :: T :: T :: T :: T :: shapeless.HNil
[error]     paGen.from(prHlist.tail)
And https://dotty.epfl.ch/docs/reference/metaprogramming/inline.html#the-scalacompiletimeops-package
It's much better. You can do arithmetic operations on primitive types.
Ethan
@esuntag
Ah nice. In that case I think it should have feature parity with Shapless's Nat
Markus Appel
@markusa380

I have a weird problem with Poly1...


implicit val putUrl: Put[Url] = Put[String]
    .contramap[Url](url => ju.Base64.getEncoder().encodeToString(url.getBytes("utf-8")))  

object toFragmentPoly extends shapeless.Poly1 {
    implicit def default[A](implicit put: Put[A]) = at[A](a => fr0"$a")
  }

(Put as in doobie)

And when I apply it to a HList .map which has Put instances for all included types in scope (most of them are default, only putUrl is for my own custom type) I get a RUNTIME error:

java.lang.NoSuchMethodError: pangea.backend.dao.package$.putUrl()Ldoobie/util/Put;

??????????????
Ethan
@esuntag
That looks like some sort of build error to me. Is doobie included in the jar?
Markus Appel
@markusa380
I'm just running sbt test
And pangea.backend.dao is the package object the above code snippet is in
You know what you might be right, let me check something
Yes, I had a package object in my test sources with the exact same name as the one from the main sources
Thanks @esuntag
Ethan
@esuntag
Np, glad you got it worked out