score:86
You can also write
(Person.apply _).tupled
to avoid repeating the types.
score:4
To build on some of the other comments you could do the following as well since tuple is calling the generated default apply method for the case class.
object Person {
...
def tupled = (this.apply _).tupled
}
score:7
One workaround is define a companion object as follows:
object Person extends((String,String) => Person) {
...
}
See. https://groups.google.com/d/msg/scala-user/jyWBMz5Qslw/Bryv4ftzRLgJ
score:25
This is very similar to what Alexey Romanov said, but in order to avoid lifting apply
whenever you need tupled
, we just add it to our companion objects.
object Person {
def something = "rawr"
def tupled = (Person.apply _).tupled
}
Now you can call Person.tupled
just like you would have if it didn't have a companion object.
Source: stackoverflow.com
Related Query
- Using .tupled method when companion object is in class
- Compile error when using a companion object of a case class as a type parameter
- Return class instance using generic inside companion object for method specified in trait
- method name qualification when using a companion object
- Can't access method of companion class from companion object
- Method is tail recursive when defined on object but not on class
- Scala what is the difference between defining a method in the class instead on the companion object
- Why is my companion object cannot access method in its companion class
- In scala, how to avoid class method hiding by companion object
- Using New Keyword inside apply method in a companion object
- How to "extend" factory methods when extending class with companion object with factory methods
- StackOverflowError When Calling RDD#toDS Using Java Object Instead of a Scala Case Class
- Access companion object from case class (or vice-versa) using scala type macros
- Why can a companion object access a private val in its companion class when compiling, but cannot do that when interpreting?
- Instantiating a class using companion object
- How to call the object method (not class method) using reflection in scala
- Type mismatch on moving method from companion object to a class
- Unable to create companion class instance in companion object method
- Can I access Companion Object properties in the Companion Class using Scala
- Why Scala reports error if does not specify this.type when using chain method in inherited class
- Type mismatch when using Scala case class constructor as a method call
- Access inner class method with "fine" syntax in Java using Scala class & object
- Use scala macros to copy method from class to companion object
- Create a companion object that mixes in a trait that defines a method which returns an object of the object's companion class
- How to update a mongo record using Rogue with MongoCaseClassField when case class contains a scala Enumeration
- Scala: How do I dynamically instantiate an object and invoke a method using reflection?
- How do I call a Scala Object method using reflection?
- Get companion object of class by given generic type Scala
- Scala - No TypeTag Available Exception when using case class to try to get TypeTag?
- Scala: order of definition for companion object vs case class
More Query from same tag
- Performance of tail function for Scala Arrays
- Play Scala Activator Server having errors while serving requests because of @Inject not working
- Adding and removing dependencies with SBT and Scala IDE
- how to normalize a `scala.reflect.api.Types.Type`
- How can I make an instance of a Kleisli of an EitherT in Scala Cats?
- NoSuchMethodError when calling java code from scala
- scala count groupBy results
- Deferring implicit resolution in macros
- Setting the table name dynamically in Slick 3.x
- Treating a case class as a product for the purposes of mzero
- Print Set in Scala
- How to align Shapeless records?
- What this meas in scala?
- Check if Scala class is instance of T
- Extracting numbers in 9+.9* format from text with Scala regex
- Identify empty JSON files with Spark 2.4
- How to create a Spark DataSet when the transformation is not 1:1, but 1:many
- Mapping over collections and returning the same type of container as the input
- Calling Thread.sleep inside an actor
- Scala: "Genericising" over singleton types?
- Deriving arbitrary function instances using shapeless-scalacheck
- Storing long quasiquote matchers in a variable
- In Scala, Is tuple syntax part of language itself or an implicit constructor call on TupleN?
- scala implicit class method type mismatch in reduce vs non-implicit method with function currying
- How do I delete a parquet file in spark scala?
- How to use my classes from Scala worksheet in IntelliJ CE with Scala plugin?
- How to restrict a method only to being used with a specific type?
- This Akka stream sometimes doesn't finish
- What's the correct way to convert from StringBuilder to String?
- Stars and string combination pattern in Scala