Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Julia: Create anonymous functions using do block

In previous post, I explained Anonymous functions. You can create Anonymous Function using do statement also.

map((x) -> x^3, [1, 2, 3, 4, 5])

Above anonymous function is used to calculate x^3. Same anonymous function can be written like below.

map([1, 2, 3]) do x
    x^3
end
julia> map([1, 2, 3]) do x
x^3
end
3-element Array{Int64,1}:
1
8
27

julia> map((x) -> x^3, [1, 2, 3, 4, 5])
5-element Array{Int64,1}:
1
8
27
64
125

do x : Create an anonymous function with argument x.
do x, y : Create two argument anonymous function.


Previous                                                 Next                                                 Home


This post first appeared on Java Tutorial : Blog To Learn Java Programming, please read the originial post: here

Share the post

Julia: Create anonymous functions using do block

×

Subscribe to Java Tutorial : Blog To Learn Java Programming

Get updates delivered right to your inbox!

Thank you for your subscription

×