Pipe and map seem like related but orthogonal concepts; I don't know if
they ought to be given the same operator. But I may just be looking at
things wrongly.
I'd sooner see a tricked-out array comprehension syntax. Something like
![ add_one(x) for x in A ]
If the target array were ambiguous, one could write
!A[ f(add_one(x), add_two(y)) for x in A, y in B]
which could play well with some shorthand for taking a comprehension over
the entirety of an array, e.g.
![ add_one(.A) ]
or
!A[ f(add_one(A[.i]), add_two(B[.i])) ]
On Tuesday, June 9, 2015 at 8:37:51 PM UTC-4, Tom Breloff wrote:
>
> Stefan: Yes that's obviously valid. Simon's "foreach" is essentially what
> I mean.
>
> Although overriding the pipe operator would probably break things, I think
> ideally there would be a built-in solution that looks similar to this:
>
>
> julia> |>(A::AbstractArray, f::Function) = (for x in A; f(x); end; A)
> |> (generic function with 7 methods)
>
> julia> type MyType; x::Int; end
>
> julia> add_one!(mt::MyType) = mt.x += 1
> add_one! (generic function with 1 method)
>
> julia> A = map(MyType, 1:2)
> 2-element Array{MyType,1}:
> MyType(1)
> MyType(2)
>
> julia> A |> add_one! |> add_one!
> 2-element Array{MyType,1}:
> MyType(3)
> MyType(4)
>
>
>
>