Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jul 31 05:54
    pgrandjean opened #1265
  • Jul 31 05:51
    pgrandjean opened #1264
  • Jul 22 14:26
    joroKr21 commented #1200
  • Jul 22 14:22
    SethTisue commented #1200
  • Jul 22 13:18
    Katrix synchronize #1200
  • Jul 20 09:56

    joroKr21 on main

    Remove refinement from Witness.… Merge branch 'main' into witnes… Merge branch 'main' into witnes… and 2 more (compare)

  • Jul 20 09:56
    joroKr21 closed #1240
  • Jul 20 09:10
    milessabin commented #1240
  • Jul 19 17:41
    joroKr21 commented #1240
  • Jul 19 17:41
    joroKr21 synchronize #1240
  • Jul 14 05:59

    joroKr21 on main

    Update sbt to 1.7.1 Merge pull request #1263 from s… (compare)

  • Jul 14 05:59
    joroKr21 closed #1263
  • Jul 13 23:00
    scala-steward opened #1263
  • Jul 10 12:03

    joroKr21 on main

    Update junit-plugin, junit-runt… Revert commit(s) ca4fe1de Merge branch 'main' into update… and 2 more (compare)

  • Jul 10 12:03
    joroKr21 closed #1262
  • Jul 09 23:27
    scala-steward synchronize #1262
  • Jul 08 08:18

    joroKr21 on main

    Update sbt-scalajs, scalajs-com… Merge branch 'main' into update… Merge pull request #1260 from s… (compare)

  • Jul 08 08:18
    joroKr21 closed #1260
  • Jul 08 08:06
    joroKr21 synchronize #1260
  • Jul 08 08:06

    joroKr21 on main

    Update scala-compiler, scala-li… Merge pull request #1261 from s… (compare)

David Hoyt
@davidhoyt
I actually don't care about preserving order, but bonus points if it does. I am inclined to think that it preserves it.
Fabio Labella
@SystemFw
res1: String = a = A, b = 1, f = 2, g = G, e = 3
that's the result
however, describer probably needs some modification, it doesn't compile if your case classes have Lists in them
but the basic idea is there
mm, no, there'a problem
but it's a problem with the whole idea, not with the implementation
what do you want the behaviour to be if your classes contain things like List Option, and in general, data types with alternatives?
David Hoyt
@davidhoyt
@SystemFw I would derive a type class for it. e.g.: https://scalafiddle.io/sf/8e8Kbup/0
@SystemFw in that fiddle i try to do just that but it doesn't work
Fabio Labella
@SystemFw
but what do you want the result to be? there's a very easy way to have it print "b = List(1,2)" in that case
David Hoyt
@davidhoyt
I don't think I'm following then -- I want the result to be whatever the type class decides
Fabio Labella
@SystemFw
now I'm not following :)
the basic problem is this: how do you distinguish between a Baz and a List?
also note that my solution was merely for the example at the beginning, if you want different strategies for unpacking different things you are probably better off moving away from the Poly towards a custom type class (even though you get to keep, with small adaptations, most of the code in the instances)
the reason for that is my approach first flattens, then describes
Fabio Labella
@SystemFw
(btw, to have it print List(1,2) just add <: HListto the R type parameter in kv)
if you want Lists to be printed differently, e.g. 1..2, add an instance to describer
David Hoyt
@davidhoyt
@SystemFw please see my fiddle here: https://scalafiddle.io/sf/8e8Kbup/1
it is not picking up and using forTraversable()
@SystemFw so I do want Lists to be printed differently which is why I added an implicit def to construct a type class for List[Int]. it should display lists as [1,2]
Fabio Labella
@SystemFw
the way my approach works, you don't write down any more instances for Describe
because Describe is not being resolved recursively
(you could do it that way, but you need to change my code first)
I can tweak it to accommodate your use case I think
so, iterables should be [1,2,3] and so on right? or [1] if they have one element
David Hoyt
@davidhoyt
@SystemFw it's supposed to be a type class so I could change the output by changing which implementation is implicitly available. my fiddle gives my default implementation.
Fabio Labella
@SystemFw
right (just a thing, if you have multiple implementations for the same type, it's not technically a type class)
anyway what you want can be done with my approach
but it would probably be cleaner if you just used a custom, recursive typeclass instead of Polys
@davidhoyt I don't have any more time to write code I'm afraid, but I can tell you how to do it :)
first, add add <: HList to the R type parameter in kv
second, you need to modify base in LowPrioDescriber to take an implicit f: Format[V]where Format is a typeclass that converts types to String
then you replace .toString with f(x: V)
Fabio Labella
@SystemFw
add implementations of Format for Lists to get what you want. Add a lower priority implementation for anything that just uses toString to get the default behaviour for other values
if Format sounds similar to Describe, it's because it is! Hence my point about all this being probably better if rewritten from scratch as a recursive typeclass
However, you can reuse my code to implement what you wanted in your original question, i.e. how to flatten arbitrarily nested case classes, while preserving their LabelledGeneric#Repr type to get access to the field names later
David Hoyt
@davidhoyt
@SystemFw did it -- appears to be working thanks :) looks like it doesn't work on HLists themselves though. here's the latest: https://scalafiddle.io/sf/8e8Kbup/4
i guess it doesn't work on HList since it can't create LabelledGeneric for the example I tried. makes sense. :)
@SystemFw this is all I need it to do -- anything else to be gained by rewriting?
looks like it won't work with coproducts :/
David Hoyt
@davidhoyt
think I can figure that part out though... thanks again!
Fabio Labella
@SystemFw
it can also be made to work with Coproduct I think...but it's past 2 here, so I guess you're on your own ;)
You're welcome :)
Antonio Fijo
@afijog
Hello, I am using a Generic.Aux[CaseClass, Repr] in my code and everything is ok. Anyhow, if I change to LabelledGeneric it fails at compile time. Any idea? Is there any constraint with the labelled version?
Fabio Labella
@SystemFw
@afijog You need to give more details , since the problem is probably somewhere else in the implicit derivation chain
Antonio Fijo
@afijog
I am playing with a file of about 200 lines. How do you recommend sharing it?
I am trying to modify a CSV parser library
Antonio Fijo
@afijog
implicit def caseClassParser[Case, Repr <: HList] (implicit gen: LabelledGeneric.Aux[Case, Repr], reprParser: Lazy[CsvParser[Repr]]): CsvParser[Case] = { instance(reprParser.value.size) { cells => reprParser.value.parse(cells).right.map { parsed => (gen.from(parsed)) } } { c => reprParser.value.to(gen.to(c)).init } }
if gen is Generic, it works, but LabelledGeneric does not
Case is supposed to work for case classes
Fabio Labella
@SystemFw
@afijog a github link is probably the best way
the individual elements of a Repr have a different type in Generic and LabelledGeneric, since in the latter the type also carries evidence of the field names