From e794020d8b881ede726338be50eaa461a134889f Mon Sep 17 00:00:00 2001 From: Charles Cabergs Date: Sun, 20 Jun 2021 20:10:05 +0200 Subject: Refactoging julia problems with function chainning --- julia/002-even_fibonacci_numbers.jl | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) (limited to 'julia/002-even_fibonacci_numbers.jl') diff --git a/julia/002-even_fibonacci_numbers.jl b/julia/002-even_fibonacci_numbers.jl index 052d20d..2b4b562 100644 --- a/julia/002-even_fibonacci_numbers.jl +++ b/julia/002-even_fibonacci_numbers.jl @@ -24,17 +24,12 @@ function fib(n) end # https://stackoverflow.com/questions/56137634/function-chaining-in-julia -# need curried functions -# ( (fib(n) for n in 1:1_000_000) -# |> takewhile(<(4_000_000)) -# ) -println(sum( - Iterators.filter( - x -> x % 2 == 0, - takewhile( - <(4_000_000), - fib(n) for n in 1:1_000_000 - ) - ) -)) +result = ( + (fib(n) for n in 1:1_000_000) + |> r -> takewhile(<(4_000_000), r) + |> r -> Iterators.filter(x -> (x % 2) == 0, r) + |> sum +) + +println(result) -- cgit