16. Impure
• May change the global state (variable)
file = “/path/to/file”
function read_file()
f = open(file)
return readlines(f)
end
read_file()
17. Pure
• No side effect
function read_file(file)
f = open(file)
return readlines(f)
end
filename = “/path/to/file”
read_file(filename)
18. Impure
• There are hidden and mutable states (variables) inside the class
• Sometimes, it is difficult to reason about.
customer.setName(newName)
name = customer.getName()
19. Pure
• Good to reason about
newCustomer = setCustomerName(aCustomer, newName)
name = getCustomerName(aCustomer)
20. More practical benefits
• Laziness
• Cacheable results
• No order dependencies
• Easy to parallelize
25. Types are not class
• Types are cheap and classes are expensive!
• Types are static and classes are dynamic.
• Julia use Type, not Class.
• One can perform object-oriented design in Julia and easily write
it in functional style.
31. Lambda expression (function)
• Anonymous function
• Function as first-class citizen
() -> println()
x -> x + 5
(x, y, z) -> x + y + z
func = x -> x * 2
53. More functional properties
• Recursion is better than iteration
• Relies on the language design
• Lazy evaluation
• Use Task to help you.
• Closure
• OK
• Curry
• OK
• Pattern matching
• use multiple dispatch in Julia
57. Reactive programming in Julia
• Reactive.jl
• I hope…
source = [1, 2, 3, 4, 5, 6, 7, 8]
result = from(source)
(map, x -> x ^ 2)
(filter, x -> x > 20)
(reduce, (x, y) -> x + y)
(subscribe)