scala-hamsters / hamsters

A mini Scala utility library
Apache License 2.0
291 stars 23 forks source link

Generate def list of Enumerable with a macro #45

Closed dgouyette closed 6 years ago

dgouyette commented 7 years ago

For now, you need to explicitly and manually write the following method

implicit val seasonEnumerable = new Enumerable[Season] {
  override def list: List[Season] = List(Winter, Spring, Summer, Fall)
}

What's happen when i add another value. If we generate this method with a macro (annotation vs def macros...), that could help.

loicdescotte commented 7 years ago

Excellent idea! With a macro it would be a very powerful feature.

loicdescotte commented 6 years ago

We could use https://github.com/mrvisser/sealerate to get the list of values, or make something similar.

loicdescotte commented 6 years ago

I've added a test exemple for sealerate : https://github.com/scala-hamsters/hamsters/blob/master/shared/src/test/scala/io/github/hamsters/EnumSpec.scala#L56-L65

For the next major it would be good to have a Set instead of a list for the instance list method (as sealerate returns a Set and as it does not make sense to have duplicates in this list).