Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Oct 03 20:46
    joroKr21 synchronize #1273
  • Sep 29 14:47

    joroKr21 on main

    Massively simplify build - R… Merge branch 'main' into rebuild Merge pull request #1275 from j… (compare)

  • Sep 29 14:47
    joroKr21 closed #1275
  • Sep 20 00:39
    joroKr21 synchronize #1273
  • Sep 20 00:39
    joroKr21 synchronize #1275
  • Sep 19 22:08

    joroKr21 on main

    Update scala-compiler, scala-li… Merge branch 'main' into update… Merge pull request #1278 from s… (compare)

  • Sep 19 22:08
    joroKr21 closed #1278
  • Sep 19 22:00
    joroKr21 synchronize #1278
  • Sep 19 21:59

    joroKr21 on main

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

  • Sep 19 21:59
    joroKr21 closed #1277
  • Sep 19 21:52
    joroKr21 synchronize #1277
  • Sep 19 21:51

    joroKr21 on main

    Update sbt-mima-plugin to 1.1.1 Merge pull request #1276 from s… (compare)

  • Sep 19 21:51
    joroKr21 closed #1276
  • Sep 19 19:18
    scala-steward opened #1278
  • Sep 19 19:17
    scala-steward opened #1277
  • Sep 19 19:17
    scala-steward opened #1276
  • Sep 17 20:23
    joroKr21 assigned #1275
  • Sep 17 20:23
    joroKr21 review_requested #1275
  • Sep 17 20:23
    joroKr21 labeled #1275
  • Sep 17 20:08
    joroKr21 opened #1275
Fabio Labella
@SystemFw
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
depending on how the rest of the code was written, it might or might not work with both
in this case, it apparently doesn't :)
Antonio Fijo
@afijog
At the end of the file, I would like to use a LabelledGeneric with caseClassParser class in order to have a way to get Parser.header automatically derived.
Fabio Labella
@SystemFw
@afijog what's header? I don't see any header in the file, apart from a boolean flag
Fabio Labella
@SystemFw
@afijog change the hlist instance to this:
 implicit def hconsParser[K <: Symbol, V, Tail <: HList](implicit hParser: Lazy[CsvParser[V]], tParser: Lazy[CsvParser[Tail]]): CsvParser[FieldType[K,V] :: Tail] = {
    instance(hParser.value.size + tParser.value.size) { cells =>
      val (headCells, tailCells) = cells.splitAt(hParser.value.size)
      for {
        head <- hParser.value.parse(headCells).right
        tail <- tParser.value.parse(tailCells).right
      } yield field[K](head) :: tail
    }
  }
if you want to access the name of the key, add an implicit key: Witness.Aux[K], and call key.value.name to get the String corresponding to the field name
I've only tested that it compiles when resolving a typeclass instance for a case class, not the actual behaviour, but that's the way to do it generally
Fabio Labella
@SystemFw
also (random tips coming ), I don't think you need Lazy for the tail. You can use scalaz or cats to access Validation instead of Either, which will give you all the parsing errors (not just the first), but you'd have to change the for comprehensions to use |@| instead. Finally, with the scalaz or type level mouse libraries you already get functions to parse primitives into Validation, to simplify your primitives parsers code. Also, I'd recommend against Seq and use Vector or List, as well as making the handling of commas a bit more robust wrt whitespace. Hope you don't mind these suggestions :)
also, if you are in scala 2.12 you don't need the rightprojection to operate on either anymore, and cats add implicit enrichments to get the same behaviour in previous versions as well
Antonio Fijo
@afijog
@SystemFw Thanks for that. Actually this is not my library. I am just playing with it. :smile: The field[K](head) does not compile with error 'not found: value field' Regarding the random tips, they are welcomed :clap:
Fabio Labella
@SystemFw
oops sorry @afijog
import shapeless.labelled._
Antonio Fijo
@afijog
@SystemFw Seems to be working!! Thanks a lot again! I will try the Validation thing later!
Fabio Labella
@SystemFw
you're welcome :)
Oron Port
@soronpo
@milessabin Is it possible to make Witness work in the following case?
  def foo(r : Int)(implicit i : shapeless.Witness.Aux[r.type]) : Unit = {}
  val one = 1
  foo(one)
  foo(one + one) //fails