question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Any way to get rid of the val values = findValues boilerplate?

See original GitHub issue

Hey there,

Nice library! Wouldn’t it be possible to eliminate the need for val values = findValues by simply extending EnumEntry? Why is this needed?

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
bertderbeckercommented, Jul 7, 2017

Hey, I have written a little macro annotation with scalameta:

class AutoFindValues extends StaticAnnotation {

  inline def apply(defn: Any): Any = meta {
    defn match {
      case obj @ Defn.Object(mods, name, templ) =>
        obj.copy(templ = templ.copy(stats = templ.stats.map(_ :+ q"val values = findValues;")))
      case _ =>
        println(defn.structure)
        abort("@AutoFindValues must annotate an object.")
    }
  }
}

Does it work for you?

0reactions
lloydmetacommented, Jul 7, 2017

@i-am-the-slime ah yeah, unfortunately we can’t put findValues as a lazy val on the base class because the macro expansion gets invoked, at which point the macro doesn’t know what the implementing superclass will be. If I remember correctly, I’ve experimented with this in the past and it seems to work if I make it a def values = findValues instead, but that means a new list gets constructed on every call, which seems wasteful.

@bertderbecker that’s a neat trick 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Remove the boilerplate | Better world by better software
Let me show how to remove a lot of boilerplate code from your programs, while preserving or even clarifying its meaning.
Read more >
boilerplate free projection of case class to change data type of ...
I have an Enumeratum enum and need to load it into a spark data frame. ... Foo extends Enum[Foo] { val values =...
Read more >
plokhotnyuk/jsoniter-scala - Gitter
Create case class with default parameter value; Parse JSON that the value does not match the case class parameter variable; Skip the field...
Read more >
Validated Configurations with Ciris - Typelevel
In this blog post, we'll take a look at configurations with configuration files, to see how we can make the loading process less...
Read more >
KeyValueX: Eliminate boilerplate code and make Android ...
//Configs no longer define a bunch of KEY, VALUE constants and get, put, init static methods, Just a piece of KeyValue static variable:...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found