Learn how to write and use functional one-liners in Julia, a powerful and expressive programming language. This article covers a variety of common tasks, from manipulating arrays and strings to generating random numbers and validating data. Whether you're a beginner or a seasoned pro, you'll learn how to write more concise and efficient Julia code with functional one-liners.

Being such an expressive language, it is easy when programming Julia to start thinking:

Isn’t there an even more conscience and elegant way of solving this problem?

A lot of problems can be solved straightforward with approaches you are used to from other languages. However in Julia there is often an even shorter and clearer way to do things.

Partial Application

Partial application of a function or currying is something that was popularized by Haskell. It means by not providing all the arguments you can return a new function taking the rest of the arguments.

This may sound confusing, so let me give some examples. Normally you would do a comparison like this:

julia> 3 < 4
true

Which is identical to this, because almost everything in Julia is a function:

julia> <(3, 4)
true

What happens if you don’t provide all the arguments?

julia> <(4)
(::Base.Fix2{typeof(<),Int64}) (generic function with 1 method)

What you get instead is a callable object. We can store this, and use it later:

julia> f = <(4);

julia> f(3)
true

How is this useful? It makes is really elegant to work with functions such as map, filter and reduce.

#functional-programming #one-line #julialang #programming

Functional One-Liners in Julia
12.45 GEEK