Can methods, taking one argument, be used with infix syntax?
Explanation
Get an explanation when it's available:
Theory
  • Arity-1
    Scala has a special syntax for invoking methods of arity-1 (one argument):
    names.mkString(",")
    // is the same as
    names mkString ","
    
    This syntax is formally known as “infix notation”. It should only be used for purely-functional methods (methods with no side-effects) - such as mkString -or methods which take functions as parameters - such as foreach:
    // right!
    names foreach (n => println(n))
    names mkString ","
    optStr getOrElse ""
    // wrong!
    javaList add item
    Read more: Scala documentation: Method Invocation

Слідкуй за CodeGalaxy

Мобільний додаток Beta

Get it on Google Play
Зворотній Зв’язок
Продовжуйте вивчати
тести з Scala
Cosmo
Зареєструйся Зараз
або Підпишись на майбутні тести