Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Adam Warski
    @adamw
    hello, world! :)
    Gabriel Ciuloaica
    @devsprint_twitter
    Hi, just started with magnolia. I’m trying to implement a generic derivation from a Row to a case class instance. A Row is a list of strings. Is there an example that I can use to learn how to use mganolia?
    Kacper Korban
    @KacperFKorban
    Hi, sorry for the terrible response time. src/examples contains usage examples and is a good starting point. You should choose the branch depending on the version of Scala you are using- scala3/scala2.
    Tim Pigden
    @TimPigden
    Hi, just trying to figure out magnolia 1 / scala 3. Scarily different. The readme example says Tree derives Print - but in old magnolia the typeclass mechanism was independent of the ADTs - so we did the (for example sql, xls, json, xml, csv) derived codecs of things that didn't know it was going to happen to them. Is this still the case? (PS I'm on scala 3 hour 1 of attempting to convert stuff)
    and I see Foo derives Csv in the examples
    Tim Pigden
    @TimPigden
    ok, now looking at tests. I should be able to work my way through.
    Tim Pigden
    @TimPigden

    what am I missing?

    package tsp.csv
    import magnolia1.*
    import tsp.csv
    import CsvParser1.*
    
    trait CsvParser1[T] {
      def parse(s: String): T
    }
    
    /**
     * First parser assumes no headers and columns match case class field ordering
     */
    object CsvParser1 extends AutoDerivation[CsvParser1]:
    
      override def split[T](ctx: SealedTrait[CsvParser1, T]): CsvParser1[T] = ???
    
      override def join[T](ctx: CaseClass[CsvParser1, T]): CsvParser1[T] = value =>
        val items = value.split(" *, *")
        println(s"got items $items")
        ctx.construct { param =>
          param.typeclass.parse(items(param.index))
        }
    
      given CsvParser1[String] = (s: String) => s
      given CsvParser1[Int] = _.toInt
    
    object TestCompile:
      case class IntStuff(i: Int)
    
      val parser = CsvParser1.derived[IntStuff]

    I get

    /home/tim/code/magnolia-scala-3/optrak-config/src/main/scala/tsp/csv/CsvParser1.scala:30:16
    Compiler bug: `summonInline` was not evaluated by the compiler
      val parser = CsvParser1.derived[IntStuff]
    ahah! scala 3.0.1 was what i was missing
    Tim Pigden
    @TimPigden
    ok, another question. What about opaque types? We use them a lot (we used to use tagged types). Do we need to do them individually?
    never mind, a colleague has just pointed me to the Issues in github