Understanding what 'type' keyword does in Scala

后端 未结 4 1555
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-07 07:25

I am new to Scala and I could not really find a lot about the type keyword. I am trying to understand what the following expression may mean:

ty         


        
4条回答
  •  忘掉有多难
    2020-12-07 07:54

    Yes, the type alias FunctorType is just a shorthand for

    (LocalDate, HolidayCalendar, Int, Boolean) => LocalDate

    Type aliases are often used to keep the rest of the code simple: you can now write

    def doSomeThing(f: FunctorType)
    

    which will be interpreted by the compiler as

    def doSomeThing(f: (LocalDate, HolidayCalendar, Int, Boolean) => LocalDate)
    

    This helps to avoid defining many custom types that are just tuples or functions defined on other types, for example.

    There are also several other interesting use cases for type, as described for example in this chapter of Programming in Scala.

提交回复
热议问题