|
|
|
|
|
by tastyminerals2
2050 days ago
|
|
Implicits are not encouraged in our code base and for a good reason. This was just an example. It's not about filter at all but the general method chaining. Here is example from D if I must: real[] fun(int[] arr) {
return arr.map!(a => a.to!double / PI).array;
}
void main()
{
int[] arr = 100.iota.array; // [0, 1, 2, 3, ...]
real[] newArr = arr.map!(a=> a*2).array.fun); // [0, 0.63662, 1.27324, ...]
}
I don't know how you can chain a custom method "fun" to the output of the "map" in Scala without duck typing. Why is this not possible when all conditions type-wise are met? Why you can chain std methods like map, filter, reduce, fold etc. but not custom ones? |
|
This is maybe not exactly as convenient, but it comes pretty close.
"someA.someB.someC" becomes "someA |> someB |> someC".