score:1
Accepted answer
First of all, solving something for tuples of any arity in Scala is nasty because the tuple classes are distinct, so you'd have to have 8 or 22 or whatever arity you want to support conversions.
But anyways, tuples are for heterogeneously typed things, whereas you here require a collection of a common type. So while tuple syntax may look nice, I would recommend not to try to use it for this case in your DSL. Stick to collections or just alias your Group
type, even at the price of an additional character, e.g.
object A {
implicit def fromString(name: String) = A(name)
}
case class A(name: String)
case class Group(elem: A*)
val G = Group
G("a1", "a2")
If you really want to support tuples, the following will do:
object Group {
implicit def fromTuple2[A1 <% A, A2 <% A](t: (A1, A2)) = Group(t._1, t._2)
}
case class Group(elem: A*)
("a1", "a2"): Group
Source: stackoverflow.com
Related Query
- Internal DSL in Scala tuple to a class conversion
- Scala 3: Deriving a typeclass for conversion between a case class and a tuple type
- Packing scala tuple to custom class object
- Groovy vs Scala for internal DSL
- Difference between conversion with implicit function and implicit class in Scala
- How to do generic tuple -> case class conversion in Scala?
- Scala case class conversion
- Conversion of Scala class to javascript using jscala
- Unpacking tuple directly into class in scala
- Request body to case class conversion in play & scala
- Scala REPL personalization for internal DSL
- Use scala reflection to initiate class with internal objects
- Scala selects wrong implicit conversion from within implicit class method
- Converting a Scala implicit conversion method to a 2.10 implicit class
- How to do type conversion with the Scala Camel DSL
- Scala Map to Case Class conversion
- Scala 3 - tuple from nested case class
- play scala tuple form with multiple case class mapping in views
- scala playframework json implicit case class conversion
- Scala tuple unpacking for constructors with abstract class for inheritance
- generics with implicit class conversion scala
- Scala Internal Class Typing - Type Mismatch Error
- Sealed trait class conversion in Scala
- Scala Implicit Conversion for companion object of extended class
- scala type conversion to java generic class
- scala unpack tuple into case class arguments and additional zip two sequences
- Internal case class in scala
- Difference between object and class in Scala
- IntelliJ Scala Plugin's case class indentation is absurd
- Unable to create Scala class on IntelliJ
More Query from same tag
- Avoiding to instantiate object in test files
- Play with jquery autocomplete proper usage
- Why JAXB Moxy throws ArrayIndexOutOfBoundsException?
- When does the Stream subscriber cancel the subscription?
- Scala - Is there a function to map Seq[A] => Seq[Either[Throwable, B]]?
- When to use the equals sign in a Scala method declaration?
- How to apply custom logic inside an aggregate function
- akka streams with spark streaming: messages are not delivered to actor; getting dead letters
- Using guice when creating a custom Action using ActionBuilder in play
- Pattern matching with more than one match
- Spark Dataframe extracting columns based dynamically selected columns
- How does one replace the first matching item in a list in Scala?
- ScalaTest AsyncFunSuiteLike multiple asserts
- Can Scalas manifest.erasure be correctly typed?
- How to drop nested column or filter nested column in scala
- How to return http Result in play framework in case of recovering future?
- error: ';' expected but double literal found
- How to convert scala Array to Java array []
- How to convert, in Scala, an Array[VertexIds] to a Map?
- Rotating text using Textrenderer
- Executing custom function on MongoDB using Casbah/Scala
- How could I know if a database table is exists in ScalaQuery
- How can I force Spark to execute code?
- Parse a JSON FILE in Scala(2.10.1) using Play
- Scala Option: Usage of unless with getOrElse
- Create A singletonSet Function Which Creates A Singleton Set From One Integer Value In SCALA
- Replace an element in a sorted set in scala
- Cross-language (python to scala) sparse data ser/deser?
- Scala "overloaded method apply with alternatives" - understand method signatures
- How can I sort a dictionary by key in Scala?