[This post is inspired by this article.]
This feature is nice, but I strongly believe that this should be denoted explicitly, i.e. if you want to call
then declare it such way:
If you want to call it as
And to call it as
If you want to allow the user to use
This feature is nice, but I strongly believe that this should be denoted explicitly, i.e. if you want to call
evenNumbers
like this:
Code:
evenNumbers([1, 2, 3, 4])
Code:
F evenNumbers(Array[Int] arr)
R arr.filter(n -> n % 2 == 0)
[1, 2, 3, 4].evenNumbers()
, then declare it this way:
Code:
F Array[Int].evenNumbers()
R .filter(n -> n % 2 == 0)
[1, 2, 3, 4].evenNumbers
just remove parentheses:
Code:
F Array[Int].evenNumbers
R .filter(n -> n % 2 == 0)
If you want to allow the user to use
evenNumbers
in any of these three ways, then you should write something like this:
Code:
F evenNumbers(Array[Int] arr)
R arr.filter(n -> n % 2 == 0)
F Array[Int].evenNumbers()
R evenNumbers((.)) // `(.)` means `self`, but this line can even be shortened to `R evenNumbers(.)`
F Array[Int].evenNumbers
R evenNumbers((.))
Last edited: