Using .tupled method when companion object is in class

前端 未结 4 1033
我在风中等你
我在风中等你 2020-12-13 18:32

I am in the process of migrating from Slick to Slick 2, and in Slick 2 you are meant to use the tupled method when projecting onto a case class (as shown here h

相关标签:
4条回答
  • 2020-12-13 18:45

    You can also write

    (Person.apply _).tupled
    

    to avoid repeating the types.

    0 讨论(0)
  • 2020-12-13 18:48

    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.

    0 讨论(0)
  • 2020-12-13 18:49

    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
    }
    
    0 讨论(0)
  • 2020-12-13 18:57

    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

    0 讨论(0)
提交回复
热议问题