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
Fabio Labella
@SystemFw
example, let's say you build a typed schema with shapeless. Most of your code will have compile time guarantees about it
at the edge of your code you can say "I dynamically assert that this piece of data conforms to this schema, and will throw an error otherwise"
PhillHenry
@PhillHenry
I thought not. Thanks @SystemFw
Fabio Labella
@SystemFw

:point_up: March 6, 2019 4:26 PM

it's somewhat related to this point

Yosef Fertel
@frosforever
Hey folks, is it possible to prove some A is not a case class? I can do something like evNotCaseClass: A <:!< Product but that’s more broad than I would otherwise want it.
Yosef Fertel
@frosforever
you’ve got much better google fu than me @DmytroMitin!
guess there’s no way using shapeless constructs only?
Dmytro Mitin
@DmytroMitin
@frosforever myabe something will illTyped
Miles Sabin
@milessabin
Hmm ... I thought we did have something like that.
Dmytro Mitin
@DmytroMitin
@frosforever that link at SO shows how to check that T is a case class and negation can be done via standard trick DoesntHave https://stackoverflow.com/questions/24853615/how-in-shapeless-do-you-say-that-a-proof-is-the-empty-type-i-e-false
Yosef Fertel
@frosforever
Ohhh that looks useful too. Gotta play with that a bit. thanks!
Miles Sabin
@milessabin
Why is ruling out Products too broad? Do you want to allow tuples?
Yosef Fertel
@frosforever
In my particular case there’s a class that I want to include that’s not a case class but sadly extends Product otherwise it would be perfect
I think I might just get around it for that particular class with some Low prority implicits instead. That might be easier
Miles Sabin
@milessabin
I think that's probably the simplest approach.
Dirk T.
@DirkToewe
Why does Nat use Peano Arithmetics instead of a binary integer representation?
AndreasKostler
@AndreasKostler

Hi all, is there machinery in shapeless (or elsewhere) allowing you to prove that a particular implicit instance is NOT in scope? I.e.

trait Foo
implicit val foo = new Foo {}

implicitly[Not[Foo]] // Err: "Implicit instance for Foo in scope."

I have something that works but I'm wondering if someone thought about this in more depth before.

Jacob Wang
@jatcwang
@AndreasKostler I'm pretty sure there is. Let me take a look (good to see you again btw! :D)
AndreasKostler
@AndreasKostler
Ahhh thank you! :)
Ethan
@esuntag
I've got a code generator that produces a sealed trait with ~280 case classes extending it. I would like to use Shapeless to do some generic reasoning over this, and am currently working on a parser. However, trying to create a Generic[MyData] leads to a stack overflow. Is there any good way around this?
ritschwumm
@ritschwumm
@esuntag have you tried increasing the VMs stack size to at least -Xss2M ?
Ethan
@esuntag
I'll give that a shot
ritschwumm
@ritschwumm
@esuntag might need even more, i had cases where it required twice as much
Ethan
@esuntag
Thanks. I pumped it up to 4G, that worked. I'll play around a bit more to see where it actually needs to be
It still seems to be having issue with LabelledGeneric, but I can move forward without those for now
Dmitry Avershin
@dmitraver_twitter

hi guys, I have encountered a very interesting issue which I can't really explain but maybe somebody here faced something similar. We use Scanamo in our web application for DynamoDB access. Scanamo uses shapeless internally for conversion between case classes and dynamodb data model. Basically, for this to work there should be implicit formatter in scope for the case class, these formatters are automatically derived via shapeless. I once added a new field to my case class and noticed that tests started blocking infinitely. After hours spent debugging I found out that the place that actually hangs forever is the call to LabelledGeneric.from during the derivation phase but when I tried to evaluate this expression in Intellij debugger it showed me that there is an exception

java.lang.NoSuchMethodError: somepackage.MyCaseClass.<init>(Lscala/Option;Lscala/Option;Ljava/lang/Double;)V

what is interesting here is that this list of parameters doesn't include my new field even though its in code. What is even more interesting is that when I tried to summon the implicit for the formatter on the very high level in my application code like implicitly[DynamoFormat[MyCaseClass]] all code started working again without any blockage and even after I removed this line. When I added new fields again in future I had no problems with it but my colleagues had the same issue. To me it looks like shapeless somehow loads the old (cached somewhere?) version of case class in the situation where code blocks but why then the exception is not thrown? Has anybody seen something similar? Thanks in advance.

Thoren Johne
@thoren
looks like Shapeless is somehow addicted to a clean compile, wish it would be more handsome at that point.
ritschwumm
@ritschwumm
hm, can this be related to sbt/zinc#249 ?
elyphas
@elyphas

Hi, i am reading the book "the type astronaut's guide to shapeless" and this has written "types are too specifc", and I have a doubt, "generic" is it the same that "dynamic programming", or what would be the difference?

someone could explain this to me?, please

elyphas
@elyphas
And basically because i understand that type class is better than generic like in "standard template libraries" in c++
elyphas
@elyphas
@DmytroMitin , thank you, :) sorry
samthebest
@samthebest
Trying to automagically create case classes from Map[String, Any]
Dmytro Mitin
@DmytroMitin
@samthebest As I commented in your question at SO, for List you should define one more instance of type class. You can use instance I wrote for Option as an example. If you want this approach to work with any structures like Option, List, nested sealed traits + case classes then probably instances should be defined for arbitrary products/coproducts.
dragonfly.ai
@dragonfly-ai

Could Shapeless help to eliminate the following boiler plate?

Please consider a trait called Navigable. Any class that extends this trait must implement a method that takes a path as a parameter and returns the value at the end of the path. The path encodes steps through the object graph reachable from this object. For example, the path: "foo/8/colors/red" might correspond to this.foo(8).colors.get("red"); that is, a dot access, an array access, then a map retrieval.

We can assume constraints on Navigable objects: 1. They always consist of directed acyclic object graphs. 2. They only reference primitives, maps, arrays, and other Navigable objects.

Can shapeless eliminate the need to write path comprehension code for every single Navigable type?

Fabio Labella
@SystemFw
@dragonfly-ai you should look into lenses, like the Monocle library
dragonfly.ai
@dragonfly-ai

@SystemFw Thanks for the suggestion. I have looked into lenses and the Monocle library. If you write code to declare how they compose with each other, Lenses simulate object mutations by simplifying the process of creating copies of all of the nodes in an object graph.

How does that relate to parsing a path of the form: "foo/8/colors/red" into a series of field, array, and map accesses?

Fabio Labella
@SystemFw
because you can parse that path into an optic (not just lenses, but also traversals and so on)
samthebest
@samthebest

@DmytroMitin

You can use instance I wrote for Option as an example.

Ah OK I'll give it a whirl. Thanks for all the help!

dragonfly.ai
@dragonfly-ai
@SystemFw wouldn't I have to write Monocle code for every class that extends Navigable? Is there a Scala.js friendly way to generate that code or functionality automatically without configuration or special code?
Fabio Labella
@SystemFw
I think Monocle comes with several ways of avoiding the boilerplate. The goggles library might also be useful for that
samthebest
@samthebest

@DmytroMitin So I'm trying

implicit def hconsFromMap0list[K <: Symbol, V, R <: HList, T <: HList](implicit
                                                                        witness: Witness.Aux[K],
                                                                        gen: LabelledGeneric.Aux[V, R],
                                                                        fromMapH: FromMap[R],
                                                                        fromMapT: FromMap[T]
                                                                       ): FromMap[FieldType[K, List[V]] :: T] =
    new FromMap[FieldType[K, List[V]] :: T] {
      def apply(m: Map[String, Any]): Option[FieldType[K, List[V]] :: T] = (for {
        v <- m.get(witness.value.name)
        r <- Typeable[Map[String, Any]].cast(v)
        h <- fromMapH(r)
        t <- fromMapT(m)
      } yield field[K](List(gen.from(h))) :: t).orElse(for {
        v <- m.get(witness.value.name)
        r1 <- Typeable[List[Map[String, Any]]].cast(v)
        opt = for {
          r <- r1
          h <- fromMapH(r)
        } yield gen.from(h)
        t <- fromMapT(m)
      } yield field[K](opt) :: t)
    }

But the following test fails with NSEE None.get

case class NestedFoo(foos: Option[List[Foo]])
case class Foo(foo: String)

"NestedFoo" in {
      val map = Map[String, Any]("foos" -> Some(List(Map("foo" -> "value"), Map("foo" -> "value2"))))

      CaseClassFromMap[NestedFoo](map) must_=== NestedFoo(foos = Some(List(
        Foo(
          foo = "value"
        ),
        Foo(
          foo = "value2"
        )
      )))
    }
Dmytro Mitin
@DmytroMitin
@samthebest Well, you wrote an instance for List. So it works for case class NestedFoo(foos: List[Foo])
CaseClassFromMap[NestedFoo](Map("foos" -> List(Map("foo" -> "value"), Map("foo" -> "value2")))) \\ NestedFoo(List(Foo(value), Foo(value2)))
CaseClassFromMap[NestedFoo](Map("foos" -> Map("foo" -> "value"))) \\ NestedFoo(List(Foo(value)))
Why do you expect it to work automatically for Option[List[..]]? There's no magic here. Type class works for types for which you defined its instances.
Philipp Martini
@maphi

Hi is there a way to define an untag method like this:

implicit class Untagger[T, U](val a: T @@ U) extends AnyVal {
  def untag: T = a
}

Currently scala unfortunately infers the type with it's Tag as T

(using 2.11)
Philipp Martini
@maphi
Ok finally found a solution. Adding T as second type parameter to tag.Tagged makes this work.
samthebest
@samthebest

@DmytroMitin I guess what I'm hoping for is some magic since there are infinite number of combinations of List[List or List[Option[Option or List[List[Option etc. If there was a way to combine the type-class for List automagically with Option for any combination of nestings that would be cool.

But in case that request is impossible, it would be nice if you could help me figure out how to just get one level of nesting working. I'm a bit stuck on Option[List[. This is what I have got so far

implicit def hconsFromMap0optList[K <: Symbol, V, R <: HList, T <: HList](implicit
                                                                         witness: Witness.Aux[K],
                                                                         gen: LabelledGeneric.Aux[V, R],
                                                                         fromMapH: FromMap[R],
                                                                         fromMapT: FromMap[T]
                                                                        ): FromMap[FieldType[K, Option[List[V]]] :: T] =
    new FromMap[FieldType[K, Option[List[V]]] :: T] {
      def apply(m: Map[String, Any]): Option[FieldType[K, Option[List[V]]] :: T] = (for {
        v <- m.get(witness.value.name)
        r <- Typeable[Map[String, Any]].cast(v)
        h <- fromMapH(r)
        t <- fromMapT(m)
      } yield field[K](Some(List(gen.from(h)))) :: t).orElse(for {
        v <- m.get(witness.value.name)
        r1 <- Typeable[Option[List[Map[String, Any]]]].cast(v)
        opt = for {
          r <- r1
          h <- fromMapH(r)
          list = for {
            r2 <- r
            h2 <- fromMapH(r2)
          } yield gen.from(h2)
        } yield ???
        t <- fromMapT(m)
      } yield field[K](opt) :: t)
    }

As you can see I'm a bit confused on how to get the for-comprehensions to work with this extra level of nesting.

Again appreciate the help! I'm very new to Shapeless.