help?> |>
search: |>
|>(x, f)
Applies a function to the preceding argument. This allows for easy function chaining.
Examples
≡≡≡≡≡≡≡≡≡≡
julia> [1:5;] |> x->x.^2 |> sum |> inv
0.01818181818181818
By the way, could you help to explain the difference between [1:5] and [1:5;]? And why there should a ; in the end of [1:5;]? (Just any reference is OK.)
I guesstimate that if there is only one element in the array, we should suffix some punctuation (here is the semicolon) to indicate whether this array is an row vector, column vector.
If the arguments inside the square brackets are separated by semicolons ( ; ) or newlines instead of commas, then their contents are vertically concatenated together instead of the arguments being used as elements themselves.
This means on the other side, that [1:5] is an array with a UnitRange as the only element:
I think the main issue with your code segment is that you didn’t use a dot to broadcast the operation over the range and perform it elementwise
1:5 |> x -> x^2 # Will error, squaring a range not defined
1:5 .|> x -> x^2 # OK, passes each element of range into function
1:5 |> x -> x.^2 # also ok