SlideShare a Scribd company logo
1 of 111
Download to read offline
The Marvelous Land of
Higher Order Functions
Mike Harris
Travel Log
• Forest of Higher Order
• Reduce
• Map
• Filter
• City of Mapcat
• City of Zip
• The Emerald City of FP
Know thyself γνῶθι σεαυτόν
Croesus King of Lydia (560 - 547 BC)
–- Herodotus, The Histories
“[I]f Croesus attacked the Persians, he would
destroy a mighty empire”
Cyrus the Great founder of the Achaemenid Empire
Travel Log
• Forest of Higher Order
• Reduce
• Map
• Filter
• City of Mapcat
• City of Zip
• The Emerald City of FP
–- L. Frank Baum, The Marvelous Land of Oz
“Everything in life is unusual until you get
accustomed to it.”
f g
f(g)
Function
f
g
Function
Travel Log
• Forest of Higher Order
• Reduce
• Map
• Filter
• City of Mapcat
• City of Zip
• The Emerald City of FP
Reduce
• Reduce (Clojure, Underscore.js)
• Aggregate (C#)
• Fold (Haskell)
• Accumulate (C++)
Reducer
Collection
Result
1 2 3 4
Add
10
var sum = 0;!
var arr =!
new[] {1, 2, 3, 4};!
foreach(var x in arr)!
{!
sum += x;!
}!
!
// 10
new[] {1, 2, 3, 4}!
.Aggregate(!
0,!
!(m, x) => m += x); !
!
// 10
(reduce!!!
#(+ %1 %2) !
!!![1 2 3 4])!
!
;; 10
Travel Log
• Forest of Higher Order
• Reduce
• Map
• Filter
• City of Mapcat
• City of Zip
• The Emerald City of FP
Map
• Map (Clojure, Haskell, Underscore.js)
• Select (C#)
• Transform (C++)
Mapper
Collection
Result
1 2 3 4
Increment
2 3 4 5
new[] {1, 2, 3, 4}!
.Select(x => x+1); !
!
// { 2, 3, 4, 5 }
(map inc [1 2 3 4])!
!
;; [2 3 4 5]
(map inc [1 2 3 4])!
!
;; [2 3 4 5]
reduce
map
add to
collectionfunction
new[] {1, 2, 3, 4}!
.Aggregate(!
new List<int>(),!
(m, x) => {!
m.Add(x+1);!
return m;!
}).ToArray();!
!
// { 2, 3, 4, 5 }
new[] {1, 2, 3, 4}!
.Aggregate(!
new int[]{},!
(m, x) => m.Add(x+1));
!
// { 2, 3, 4, 5 }
FAKE C# CODE!!!
FAKE C# CODE!!!
new[] {1, 2, 3, 4}!
.Select(x => x+1); !
!
// { 2, 3, 4, 5 }
(reduce!!!
#(conj %1 (inc %2))!
[] !
!!![1 2 3 4])!
!
;; [2 3 4 5]
(map!
inc!
[1 2 3 4])!
!
;; [2 3 4 5]
Travel Log
• Forest of Higher Order
• Reduce
• Map
• Filter
• City of Mapcat
• City of Zip
• The Emerald City of FP
Filter
• Filter (Clojure, Haskell, Underscore.js)
• Where (C#)
• Remove (C++)
Filter
Collection
Result
1 2 3 4
Odd?
1 3
new[] {1, 2, 3, 4}!
.Where(x => x%2 != 0);!
!
// { 1, 3 }
(filter odd? [1 2 3 4])!
!
;; [1 3]
reduce
filter
add to
collection
predicate
new[] {1, 2, 3, 4}!
.Aggregate(!
new List<int>(),!
(m, x) => {!
if (x%2 != 0)!
m.Add(x);!
return m;!
}).ToArray();!
// { 1, 3 }
new[] {1, 2, 3, 4}!
.Aggregate(!
new int[]{},!
(m, x) => !
(x%2 != 0)!
? m.Add(x+1) : m);
// { 1, 3 }
FAKE C# CODE!!!
FAKE C# CODE!!!
new[] {1, 2, 3, 4}!
.Where(x => x%2 != 0);!
!
// { 1, 3 }
(reduce !
#(if (odd? %2)!
(conj %1 %2)!
%1)!
[] !
[1 2 3 4])!
!
;; [1 3]
(filter!
odd?!
[1 2 3 4])!
!
;; [1 3]
FizzBuzz
Kata
1 2 Fizz 4 Buzz
Fizz 7 8 Fizz
Buzz 11 Fizz 13
14 FizzBuzz 16
17 Fizz 19 Buzz
Fizz 22 23 Fizz
Buzz 26 Fizz 28
29 FizzBuzz 31
Enumerable.Range(1, 35)!
.Select(x => {!
if (x%15 == 0) return “FizzBuzz”;!
if (x%3 == 0) return “Fizz”;!
if (x%5 == 0) return “Buzz”;!
return x.ToString();!
});!
!
// { “1”, “2”, “Fizz”, “4”, “Buzz”
Enumerable.Range(1, 35)!
.Aggregate(!
new List<string>(), !
(m, x) => {!
if (x%15==0) m.Add(“FizzBuzz”);!
else if (x%3==0) m.Add(“Fizz”);!
else if (x%5==0) m.Add(“Buzz”);!
else m.Add(x.ToString());!
return m;!
});!
!
// { “1”, “2”, “Fizz”, “4”, “Buzz”
Coin Changer
Kata
Func<int[], int, int[]> changer = !
(coins, amount) => coins.Select(!
coin => { !
var c = amount / coin; !
amount %= coin; !
return c;!
}).ToArray();!
!
changer(new[] {25,10,5,1}, 99);!
!
// { 3, 2, 0, 4 }
Func<int[], int, int[]> changer = !
(coins, amount) => coins.Aggregate(!
new List<int>(),!
(m, coin) => {!
m.Add(amount / coin); !
amount %= coin; !
return m;!
}).ToArray();!
!
changer(new[] {25,10,5,1}, 99);!
!
// { 3, 2, 0, 4 }
Travel Log
• Forest of Higher Order
• Reduce
• Map
• Filter
• City of Mapcat
• City of Zip
• The Emerald City of FP
–- L. Frank Baum, The Emerald City of Oz
“[I]t is folly for us to try to appear otherwise
than as nature has made us.”
Mapcat
• Mapcat (Clojure)
• SelectMany (C#*)
• >>= (Haskell*)
* not exactly the same as Clojure’s mapcat
Mapper

Catter
Collection
Result
1 2 3 4
Identity
2 3 4 20
20 10
101
new[] {!
new[] {1, 2, 3, 4},!
new[] {20, 10}!
}.SelectMany(x => x);!
!
// { 1, 2, 3, 4, 20, 10 }
(mapcat identity !
[[1 2 3 4] [20 10]])!
!
;; [1 2 3 4 20 10]
1 2 3 4
Increment
3 4 5 21
20 10
112
new[] {!
new[] {1, 2, 3, 4},!
new[] {20, 10}!
}.SelectMany(!
x => x.Select(!
y => y+1));!
!
// { 2, 3, 4, 5, 21, 11 }
new[] {!
new[] {1, 2, 3, 4},!
new[] {20, 10}!
}.SelectMany(x => x)!
.Select(x => x + 1);!
!
// { 2, 3, 4, 5, 21, 11 }
(mapcat!
#(map inc %) !
[[1 2 3 4] [20 10]])!
!
;; [2 3 4 5 21 11]
(map inc!
(mapcat identity!
[[1 2 3 4] [20 10]])!
)!
!
;; [2 3 4 5 21 11]
(->>!
[[1 2 3 4] [20 10]]!
(mapcat identity)!
(map inc))!
!
;; [2 3 4 5 21 11]
Travel Log
• Forest of Higher Order
• Reduce
• Map
• Filter
• City of Mapcat
• City of Zip
• The Emerald City of FP
–- L. Frank Baum, The Wonderful Wizard of Oz
“Even with eyes protected by the green
spectacles, Dorothy and her friends were at
first dazzled by the brilliancy of the wonderful
City.”
Zip
• Map (Clojure)
• Zip (C#)
• ZipWith (Haskell)
Zipper
Collection Collection
Result
1 2 3
Add
10 20 30
11 22 33
new[] {1, 2, 3}!
.Zip(!
new[] {10, 20, 30},!
(x, y) => x + y);!
!
// { 11, 22, 33 }
(map + !
[1 2 3] [10 20 30])!
!
;; [11 22 33]
1 2
Add
10 20 30
11 22 ???
new[] {1, 2}!
.Zip(!
new[] {10, 20, 30},!
(x, y) => x + y);!
!
// { 11, 22 }
(map + !
[1 2] [10 20 30])!
!
;; [11 22]
1 2 3
Add
10 20
11 22 ???
new[] {1, 2, 3}!
.Zip(!
new[] {10, 20},!
(x, y) => x + y);!
!
// { 11, 22 }
(map + !
[1 2 3] [10 20])!
!
;; [11 22]
FizzBuzz
Kata
1 2 Fizz 4 Buzz
Fizz 7 8 Fizz
Buzz 11 Fizz 13
14 FizzBuzz 16
17 Fizz 19 Buzz
Fizz 22 23 Fizz
Buzz 26 Fizz 28
29 FizzBuzz 31
var inf = Enumerable.Range(0, int.MaxValue);!
var fizzes = inf.Select(x => x%3 == 0 ? “Fizz” : “”);!
var buzzes = inf.Select(x => x%5 == 0 ? “Buzz” : “”);!
var numbers = inf.Select(x => x.ToString());!
!
var fizzbuzzer = !
fizzes!
.Zip(buzzes, (f, b) => f + b)!
.Zip(numbers, (fb, n) => fb == “” ? n : fb);!
!
fizzbuzzer.Skip(33).First();!
// “Fizz”!
!
fizzbuzzer.Skip(55).First();!
// “Buzz”!
!
fizzbuzzer.Skip(150).First();!
// “FizzBuzz”!
!
fizzbuzzer.Skip(2).First();!
// “2”
var inf = Enumerable!
.Range(0, int.MaxValue);!
!
var fizzes = inf.Select(!
x => x%3 == 0 ? “Fizz” : “”);!
var buzzes = inf.Select(!
x => x%5 == 0 ? “Buzz” : “”);!
!
var numbers = inf.Select(!
x => x.ToString());
var fizzbuzzer = !
fizzes!
.Zip(buzzes,(f, b) => f + b)!
.Zip(numbers,!
(fb, n) => fb == “” ? n : fb);
fizzbuzzer.Skip(33).First();!
// “Fizz”!
!
fizzbuzzer.Skip(55).First();!
// “Buzz”!
!
fizzbuzzer.Skip(150).First();!
// “FizzBuzz”!
!
fizzbuzzer.Skip(2).First();!
// “2”
var inf = Enumerable.Range(0, int.MaxValue);!
var fizzes = inf.Select(x => x%3 == 0 ? “Fizz” : “”);!
var buzzes = inf.Select(x => x%5 == 0 ? “Buzz” : “”);!
var numbers = inf.Select(x => x.ToString());!
!
var fizzbuzzer = !
fizzes!
.Zip(buzzes, (f, b) => f + b)!
.Zip(numbers, (fb, n) => fb == “” ? n : fb);!
!
fizzbuzzer.Skip(33).First();!
// “Fizz”!
!
fizzbuzzer.Skip(55).First();!
// “Buzz”!
!
fizzbuzzer.Skip(150).First();!
// “FizzBuzz”!
!
fizzbuzzer.Skip(2).First();!
// “2”
Travel Log
• Forest of Higher Order
• Reduce
• Map
• Filter
• City of Mapcat
• City of Zip
• The Emerald City of FP
–- L. Frank Baum, The Marvelous Land of Oz
“To 'know Thyself' is considered quite an
accomplishment.”
What

!
How
Execute
Transduce
;; transducer signature!
(whatever, input -> whatever) ->
(whatever, input -> whatever)
*from: http://clojure.org/transducers
reduce
map
add to
collectionfunction
new[] {1, 2, 3, 4}!
.Select(x => x+1); !
!
// { 2, 3, 4, 5 }
new[] {1, 2, 3, 4}!
.Aggregate(!
new List<int>(),!
(m, x) => {!
m.Add(x+1);!
return m;!
}).ToArray();!
!
// { 2, 3, 4, 5 }
new[] {1, 2, 3, 4}!
.Aggregate(!
new List<int>(),!
(m, x) => {!
m.Add(x+1);!
return m;!
}).ToArray();!
!
// { 2, 3, 4, 5 }
new[] {1, 2, 3, 4}!
.Aggregate(coll!
new typeof(coll),!
(m, x) => {!
m.Step(x+1);!
return m;!
});!
// { 2, 3, 4, 5 }
FAKE C# CODE!!!
FAKE C# CODE!!!
What

!
How
Execute
Transduce
;; map

(defn map [f coll]

(reduce !
(fn [m x]!
(conj m (f x)))!
[] coll))
*from: http://youtu.be/6mTbuzafcII
;; map

(defn map [f coll]

(reduce !
(fn [m x]!
(conj m (f x)))!
[] coll))
*from: http://youtu.be/6mTbuzafcII
;; map

(defn mapping [f]!
(fn [step]!
(fn [m x]!
(step m (f x)))))!
!
(defn map [f coll]!
(reduce !
((mapping f) conj) !
[] coll))
*from: http://youtu.be/6mTbuzafcII
(defn mapping [f]!
(fn [step]!
(fn [m x]!
(step m (f x)))))
*from: http://youtu.be/6mTbuzafcII
(defn map [f coll]!
(reduce !
((mapping f) conj) !
[] coll))
*from: http://youtu.be/6mTbuzafcII
;; map

(defn map [f coll]

(reduce !
(fn [m x]!
(conj m (f x)))!
[] coll))
*from: http://youtu.be/6mTbuzafcII
;; map

(defn mapping [f]!
(fn [step]!
(fn [m x]!
(step m (f x)))))!
!
(defn map [f coll]!
(reduce !
((mapping f) conj) !
[] coll))
*from: http://youtu.be/6mTbuzafcII
–- L. Frank Baum, The Marvelous Land of Oz
“[A]lthough I feel that I know a tremendous lot, I
am not yet aware how much there is in the
world to find out about. It will take me a little
time to discover whether I am very wise or very
foolish.”
Thank you!
Mike Harris



@MikeMKH

http://comp-phil.blogspot.com/
–- L. Frank Baum, The Marvelous Land of Oz
“Everything has to come to an end, sometime.”
Bibliography (conference sessions)
• Rich Hickey - Transducers

Strange Loop 2014

https://www.youtube.com/watch?v=6mTbuzafcII
• Rich Hickey - Inside Transducers + more.async

Clojure Conj 2014

https://www.youtube.com/watch?v=4KqUvG8HPYo
Bibliography (blog posts)
• Martin Fowler - Collection Pipelines

http://martinfowler.com/articles/collection-pipeline/
• Justin Etheredge - A Visual Look at the LINQ SelectMany
Operator

http://www.codethinked.com/a-visual-look-at-the-linq-
selectmany-operator
Bibliography (white papers)
• Graham Hutton - A Tutorial on the Universality and
Expressiveness of fold

http://www.cs.nott.ac.uk/~gmh/fold.pdf
Bibliography (websites)
• Sam Allen - Dot Net Perls

http://www.dotnetperls.com/
• lots of smart people - ClojureDocs

https://clojuredocs.org/
• Rich Hickey - Transducers

http://clojure.org/transducers
Bibliography (Pluralsight classes)
• Scott Allen - LINQ Architecture

http://www.pluralsight.com/courses/linq-architecture
• Deborah Kurata - Practical LINQ

http://www.pluralsight.com/courses/practical-linq
Bibliography (books)
• Michael Fogus and Chris Houser - The Joy of Clojure

http://www.manning.com/fogus2/
Images
• [1] The International Wizard of Oz Club, http://ozclub.org/
• [3-5, 7] Wikipedia, public domain
• [9] W.W. Denslow - The Wonderful Wizard of Oz
• [47] Flicker - Jeremy Schultz, https://www.flickr.com/photos/
tao_zhyn/442965594/
• [51] W.W. Denslow - The Marvelous Land of Oz
• [65, 85] W.W. Denslow - The Wonderful Wizard of Oz
• [103] Me taken at dinner by my wife while at Strange Loop 2014

More Related Content

What's hot

The Lesser Known Features of ECMAScript 6
The Lesser Known Features of ECMAScript 6The Lesser Known Features of ECMAScript 6
The Lesser Known Features of ECMAScript 6Bryan Hughes
 
42: Rise of the dependent types
42: Rise of the dependent types42: Rise of the dependent types
42: Rise of the dependent typesGeorge Leontiev
 
Gabriele Lana - The Magic of Elixir
Gabriele Lana - The Magic of ElixirGabriele Lana - The Magic of Elixir
Gabriele Lana - The Magic of ElixirCodemotion
 
Girl Geek Dinners - Clojure 101
Girl Geek Dinners - Clojure 101Girl Geek Dinners - Clojure 101
Girl Geek Dinners - Clojure 101Logan Campbell
 
Implementing virtual machines in go & c 2018 redux
Implementing virtual machines in go & c 2018 reduxImplementing virtual machines in go & c 2018 redux
Implementing virtual machines in go & c 2018 reduxEleanor McHugh
 
The Browser Environment - A Systems Programmer's Perspective
The Browser Environment - A Systems Programmer's PerspectiveThe Browser Environment - A Systems Programmer's Perspective
The Browser Environment - A Systems Programmer's PerspectiveEleanor McHugh
 
Palestra sobre Collections com Python
Palestra sobre Collections com PythonPalestra sobre Collections com Python
Palestra sobre Collections com Pythonpugpe
 
eJADA web development the Ruby way
eJADA web development the Ruby wayeJADA web development the Ruby way
eJADA web development the Ruby wayMustafah Elbanna
 
The groovy puzzlers (as Presented at JavaOne 2014)
The groovy puzzlers (as Presented at JavaOne 2014)The groovy puzzlers (as Presented at JavaOne 2014)
The groovy puzzlers (as Presented at JavaOne 2014)GroovyPuzzlers
 
Exploring web vr ️ ♀️
Exploring web vr ️ ♀️Exploring web vr ️ ♀️
Exploring web vr ️ ♀️Sherry List
 
subversion hacks (create a commit template)
subversion hacks (create a commit template)subversion hacks (create a commit template)
subversion hacks (create a commit template)Hirohito Kato
 
Parse Everything With Elixir
Parse Everything With ElixirParse Everything With Elixir
Parse Everything With ElixirGabriele Lana
 
Getting Started With Play Framework
Getting Started With Play FrameworkGetting Started With Play Framework
Getting Started With Play FrameworkTreasury user10
 

What's hot (20)

dplyr use case
dplyr use casedplyr use case
dplyr use case
 
The Lesser Known Features of ECMAScript 6
The Lesser Known Features of ECMAScript 6The Lesser Known Features of ECMAScript 6
The Lesser Known Features of ECMAScript 6
 
42: Rise of the dependent types
42: Rise of the dependent types42: Rise of the dependent types
42: Rise of the dependent types
 
08
0808
08
 
Gabriele Lana - The Magic of Elixir
Gabriele Lana - The Magic of ElixirGabriele Lana - The Magic of Elixir
Gabriele Lana - The Magic of Elixir
 
Girl Geek Dinners - Clojure 101
Girl Geek Dinners - Clojure 101Girl Geek Dinners - Clojure 101
Girl Geek Dinners - Clojure 101
 
Implementing virtual machines in go & c 2018 redux
Implementing virtual machines in go & c 2018 reduxImplementing virtual machines in go & c 2018 redux
Implementing virtual machines in go & c 2018 redux
 
Yahoo! JAPANとKotlin
Yahoo! JAPANとKotlinYahoo! JAPANとKotlin
Yahoo! JAPANとKotlin
 
The Browser Environment - A Systems Programmer's Perspective
The Browser Environment - A Systems Programmer's PerspectiveThe Browser Environment - A Systems Programmer's Perspective
The Browser Environment - A Systems Programmer's Perspective
 
Palestra sobre Collections com Python
Palestra sobre Collections com PythonPalestra sobre Collections com Python
Palestra sobre Collections com Python
 
eJADA web development the Ruby way
eJADA web development the Ruby wayeJADA web development the Ruby way
eJADA web development the Ruby way
 
The groovy puzzlers (as Presented at JavaOne 2014)
The groovy puzzlers (as Presented at JavaOne 2014)The groovy puzzlers (as Presented at JavaOne 2014)
The groovy puzzlers (as Presented at JavaOne 2014)
 
ES6, WTF?
ES6, WTF?ES6, WTF?
ES6, WTF?
 
Exploring web vr ️ ♀️
Exploring web vr ️ ♀️Exploring web vr ️ ♀️
Exploring web vr ️ ♀️
 
subversion hacks (create a commit template)
subversion hacks (create a commit template)subversion hacks (create a commit template)
subversion hacks (create a commit template)
 
py_AutoMapMaker
py_AutoMapMakerpy_AutoMapMaker
py_AutoMapMaker
 
FizzBuzz Trek
FizzBuzz TrekFizzBuzz Trek
FizzBuzz Trek
 
Parse Everything With Elixir
Parse Everything With ElixirParse Everything With Elixir
Parse Everything With Elixir
 
Getting Started With Play Framework
Getting Started With Play FrameworkGetting Started With Play Framework
Getting Started With Play Framework
 
Fizzbuzzalooza
FizzbuzzaloozaFizzbuzzalooza
Fizzbuzzalooza
 

Similar to The Marvelous Land of Higher Order Functions

Five Languages in a Moment
Five Languages in a MomentFive Languages in a Moment
Five Languages in a MomentSergio Gil
 
Coscup2021-rust-toturial
Coscup2021-rust-toturialCoscup2021-rust-toturial
Coscup2021-rust-toturialWayne Tsai
 
All You Need is Fold
All You Need is FoldAll You Need is Fold
All You Need is FoldMike Harris
 
Map Reduce 〜入門編:仕組みの理解とアルゴリズムデザイン〜
Map Reduce 〜入門編:仕組みの理解とアルゴリズムデザイン〜Map Reduce 〜入門編:仕組みの理解とアルゴリズムデザイン〜
Map Reduce 〜入門編:仕組みの理解とアルゴリズムデザイン〜Takahiro Inoue
 
Go Containers
Go ContainersGo Containers
Go Containersjgrahamc
 
Is Haskell an acceptable Perl?
Is Haskell an acceptable Perl?Is Haskell an acceptable Perl?
Is Haskell an acceptable Perl?osfameron
 
Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語ikdysfm
 
Integral table for electomagnetic
Integral table for electomagneticIntegral table for electomagnetic
Integral table for electomagneticFathur Rozaq
 
Introducing Monads and State Monad at PSUG
Introducing Monads and State Monad at PSUGIntroducing Monads and State Monad at PSUG
Introducing Monads and State Monad at PSUGDavid Galichet
 
Thinking Functionally In Ruby
Thinking Functionally In RubyThinking Functionally In Ruby
Thinking Functionally In RubyRoss Lawley
 
関数潮流(Function Tendency)
関数潮流(Function Tendency)関数潮流(Function Tendency)
関数潮流(Function Tendency)riue
 
Learn You a Functional JavaScript for Great Good
Learn You a Functional JavaScript for Great GoodLearn You a Functional JavaScript for Great Good
Learn You a Functional JavaScript for Great GoodMike Harris
 
Crunching data with go: Tips, tricks, use-cases
Crunching data with go: Tips, tricks, use-casesCrunching data with go: Tips, tricks, use-cases
Crunching data with go: Tips, tricks, use-casesSergii Khomenko
 
A Taste of Python - Devdays Toronto 2009
A Taste of Python - Devdays Toronto 2009A Taste of Python - Devdays Toronto 2009
A Taste of Python - Devdays Toronto 2009Jordan Baker
 
Are we ready to Go?
Are we ready to Go?Are we ready to Go?
Are we ready to Go?Adam Dudczak
 
RedDot Ruby Conf 2014 - Dark side of ruby
RedDot Ruby Conf 2014 - Dark side of ruby RedDot Ruby Conf 2014 - Dark side of ruby
RedDot Ruby Conf 2014 - Dark side of ruby Gautam Rege
 

Similar to The Marvelous Land of Higher Order Functions (20)

Five Languages in a Moment
Five Languages in a MomentFive Languages in a Moment
Five Languages in a Moment
 
Coscup2021-rust-toturial
Coscup2021-rust-toturialCoscup2021-rust-toturial
Coscup2021-rust-toturial
 
All You Need is Fold
All You Need is FoldAll You Need is Fold
All You Need is Fold
 
Map Reduce 〜入門編:仕組みの理解とアルゴリズムデザイン〜
Map Reduce 〜入門編:仕組みの理解とアルゴリズムデザイン〜Map Reduce 〜入門編:仕組みの理解とアルゴリズムデザイン〜
Map Reduce 〜入門編:仕組みの理解とアルゴリズムデザイン〜
 
Go Containers
Go ContainersGo Containers
Go Containers
 
Go Containers
Go ContainersGo Containers
Go Containers
 
Basics
BasicsBasics
Basics
 
Is Haskell an acceptable Perl?
Is Haskell an acceptable Perl?Is Haskell an acceptable Perl?
Is Haskell an acceptable Perl?
 
Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語
 
Integral table
Integral tableIntegral table
Integral table
 
Integral table for electomagnetic
Integral table for electomagneticIntegral table for electomagnetic
Integral table for electomagnetic
 
Introducing Monads and State Monad at PSUG
Introducing Monads and State Monad at PSUGIntroducing Monads and State Monad at PSUG
Introducing Monads and State Monad at PSUG
 
Thinking Functionally In Ruby
Thinking Functionally In RubyThinking Functionally In Ruby
Thinking Functionally In Ruby
 
関数潮流(Function Tendency)
関数潮流(Function Tendency)関数潮流(Function Tendency)
関数潮流(Function Tendency)
 
Learn You a Functional JavaScript for Great Good
Learn You a Functional JavaScript for Great GoodLearn You a Functional JavaScript for Great Good
Learn You a Functional JavaScript for Great Good
 
Hadoop I/O Analysis
Hadoop I/O AnalysisHadoop I/O Analysis
Hadoop I/O Analysis
 
Crunching data with go: Tips, tricks, use-cases
Crunching data with go: Tips, tricks, use-casesCrunching data with go: Tips, tricks, use-cases
Crunching data with go: Tips, tricks, use-cases
 
A Taste of Python - Devdays Toronto 2009
A Taste of Python - Devdays Toronto 2009A Taste of Python - Devdays Toronto 2009
A Taste of Python - Devdays Toronto 2009
 
Are we ready to Go?
Are we ready to Go?Are we ready to Go?
Are we ready to Go?
 
RedDot Ruby Conf 2014 - Dark side of ruby
RedDot Ruby Conf 2014 - Dark side of ruby RedDot Ruby Conf 2014 - Dark side of ruby
RedDot Ruby Conf 2014 - Dark side of ruby
 

More from Mike Harris

A Divine Data Comedy
A Divine Data ComedyA Divine Data Comedy
A Divine Data ComedyMike Harris
 
Combinators - Lightning Talk
Combinators - Lightning TalkCombinators - Lightning Talk
Combinators - Lightning TalkMike Harris
 
Hiking through the Functional Forest with Fizz Buzz
Hiking through the Functional Forest with Fizz BuzzHiking through the Functional Forest with Fizz Buzz
Hiking through the Functional Forest with Fizz BuzzMike Harris
 
All You Need is Fold in the Key of C#
All You Need is Fold in the Key of C#All You Need is Fold in the Key of C#
All You Need is Fold in the Key of C#Mike Harris
 
There and Back Again
There and Back AgainThere and Back Again
There and Back AgainMike Harris
 
Testing the Next Generation
Testing the Next GenerationTesting the Next Generation
Testing the Next GenerationMike Harris
 

More from Mike Harris (8)

A Divine Data Comedy
A Divine Data ComedyA Divine Data Comedy
A Divine Data Comedy
 
Combinators - Lightning Talk
Combinators - Lightning TalkCombinators - Lightning Talk
Combinators - Lightning Talk
 
C# 7
C# 7C# 7
C# 7
 
Hiking through the Functional Forest with Fizz Buzz
Hiking through the Functional Forest with Fizz BuzzHiking through the Functional Forest with Fizz Buzz
Hiking through the Functional Forest with Fizz Buzz
 
Coding f#un
Coding f#unCoding f#un
Coding f#un
 
All You Need is Fold in the Key of C#
All You Need is Fold in the Key of C#All You Need is Fold in the Key of C#
All You Need is Fold in the Key of C#
 
There and Back Again
There and Back AgainThere and Back Again
There and Back Again
 
Testing the Next Generation
Testing the Next GenerationTesting the Next Generation
Testing the Next Generation
 

Recently uploaded

Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
software engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxsoftware engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxnada99848
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 

Recently uploaded (20)

Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
software engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxsoftware engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptx
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 

The Marvelous Land of Higher Order Functions

  • 1. The Marvelous Land of Higher Order Functions Mike Harris
  • 2. Travel Log • Forest of Higher Order • Reduce • Map • Filter • City of Mapcat • City of Zip • The Emerald City of FP
  • 3.
  • 4. Know thyself γνῶθι σεαυτόν
  • 5. Croesus King of Lydia (560 - 547 BC)
  • 6. –- Herodotus, The Histories “[I]f Croesus attacked the Persians, he would destroy a mighty empire”
  • 7. Cyrus the Great founder of the Achaemenid Empire
  • 8. Travel Log • Forest of Higher Order • Reduce • Map • Filter • City of Mapcat • City of Zip • The Emerald City of FP
  • 9.
  • 10. –- L. Frank Baum, The Marvelous Land of Oz “Everything in life is unusual until you get accustomed to it.”
  • 13. Travel Log • Forest of Higher Order • Reduce • Map • Filter • City of Mapcat • City of Zip • The Emerald City of FP
  • 14. Reduce • Reduce (Clojure, Underscore.js) • Aggregate (C#) • Fold (Haskell) • Accumulate (C++)
  • 16. 1 2 3 4 Add 10
  • 17. var sum = 0;! var arr =! new[] {1, 2, 3, 4};! foreach(var x in arr)! {! sum += x;! }! ! // 10
  • 18. new[] {1, 2, 3, 4}! .Aggregate(! 0,! !(m, x) => m += x); ! ! // 10
  • 19. (reduce!!! #(+ %1 %2) ! !!![1 2 3 4])! ! ;; 10
  • 20. Travel Log • Forest of Higher Order • Reduce • Map • Filter • City of Mapcat • City of Zip • The Emerald City of FP
  • 21. Map • Map (Clojure, Haskell, Underscore.js) • Select (C#) • Transform (C++)
  • 23. 1 2 3 4 Increment 2 3 4 5
  • 24. new[] {1, 2, 3, 4}! .Select(x => x+1); ! ! // { 2, 3, 4, 5 }
  • 25. (map inc [1 2 3 4])! ! ;; [2 3 4 5] (map inc [1 2 3 4])! ! ;; [2 3 4 5]
  • 27. new[] {1, 2, 3, 4}! .Aggregate(! new List<int>(),! (m, x) => {! m.Add(x+1);! return m;! }).ToArray();! ! // { 2, 3, 4, 5 }
  • 28. new[] {1, 2, 3, 4}! .Aggregate(! new int[]{},! (m, x) => m.Add(x+1)); ! // { 2, 3, 4, 5 } FAKE C# CODE!!! FAKE C# CODE!!!
  • 29. new[] {1, 2, 3, 4}! .Select(x => x+1); ! ! // { 2, 3, 4, 5 }
  • 30. (reduce!!! #(conj %1 (inc %2))! [] ! !!![1 2 3 4])! ! ;; [2 3 4 5]
  • 31. (map! inc! [1 2 3 4])! ! ;; [2 3 4 5]
  • 32. Travel Log • Forest of Higher Order • Reduce • Map • Filter • City of Mapcat • City of Zip • The Emerald City of FP
  • 33. Filter • Filter (Clojure, Haskell, Underscore.js) • Where (C#) • Remove (C++)
  • 35. 1 2 3 4 Odd? 1 3
  • 36. new[] {1, 2, 3, 4}! .Where(x => x%2 != 0);! ! // { 1, 3 }
  • 37. (filter odd? [1 2 3 4])! ! ;; [1 3]
  • 39. new[] {1, 2, 3, 4}! .Aggregate(! new List<int>(),! (m, x) => {! if (x%2 != 0)! m.Add(x);! return m;! }).ToArray();! // { 1, 3 }
  • 40. new[] {1, 2, 3, 4}! .Aggregate(! new int[]{},! (m, x) => ! (x%2 != 0)! ? m.Add(x+1) : m); // { 1, 3 } FAKE C# CODE!!! FAKE C# CODE!!!
  • 41. new[] {1, 2, 3, 4}! .Where(x => x%2 != 0);! ! // { 1, 3 }
  • 42. (reduce ! #(if (odd? %2)! (conj %1 %2)! %1)! [] ! [1 2 3 4])! ! ;; [1 3]
  • 43. (filter! odd?! [1 2 3 4])! ! ;; [1 3]
  • 44. FizzBuzz Kata 1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13 14 FizzBuzz 16 17 Fizz 19 Buzz Fizz 22 23 Fizz Buzz 26 Fizz 28 29 FizzBuzz 31
  • 45. Enumerable.Range(1, 35)! .Select(x => {! if (x%15 == 0) return “FizzBuzz”;! if (x%3 == 0) return “Fizz”;! if (x%5 == 0) return “Buzz”;! return x.ToString();! });! ! // { “1”, “2”, “Fizz”, “4”, “Buzz”
  • 46. Enumerable.Range(1, 35)! .Aggregate(! new List<string>(), ! (m, x) => {! if (x%15==0) m.Add(“FizzBuzz”);! else if (x%3==0) m.Add(“Fizz”);! else if (x%5==0) m.Add(“Buzz”);! else m.Add(x.ToString());! return m;! });! ! // { “1”, “2”, “Fizz”, “4”, “Buzz”
  • 48. Func<int[], int, int[]> changer = ! (coins, amount) => coins.Select(! coin => { ! var c = amount / coin; ! amount %= coin; ! return c;! }).ToArray();! ! changer(new[] {25,10,5,1}, 99);! ! // { 3, 2, 0, 4 }
  • 49. Func<int[], int, int[]> changer = ! (coins, amount) => coins.Aggregate(! new List<int>(),! (m, coin) => {! m.Add(amount / coin); ! amount %= coin; ! return m;! }).ToArray();! ! changer(new[] {25,10,5,1}, 99);! ! // { 3, 2, 0, 4 }
  • 50. Travel Log • Forest of Higher Order • Reduce • Map • Filter • City of Mapcat • City of Zip • The Emerald City of FP
  • 51.
  • 52. –- L. Frank Baum, The Emerald City of Oz “[I]t is folly for us to try to appear otherwise than as nature has made us.”
  • 53. Mapcat • Mapcat (Clojure) • SelectMany (C#*) • >>= (Haskell*) * not exactly the same as Clojure’s mapcat
  • 55. 1 2 3 4 Identity 2 3 4 20 20 10 101
  • 56. new[] {! new[] {1, 2, 3, 4},! new[] {20, 10}! }.SelectMany(x => x);! ! // { 1, 2, 3, 4, 20, 10 }
  • 57. (mapcat identity ! [[1 2 3 4] [20 10]])! ! ;; [1 2 3 4 20 10]
  • 58. 1 2 3 4 Increment 3 4 5 21 20 10 112
  • 59. new[] {! new[] {1, 2, 3, 4},! new[] {20, 10}! }.SelectMany(! x => x.Select(! y => y+1));! ! // { 2, 3, 4, 5, 21, 11 }
  • 60. new[] {! new[] {1, 2, 3, 4},! new[] {20, 10}! }.SelectMany(x => x)! .Select(x => x + 1);! ! // { 2, 3, 4, 5, 21, 11 }
  • 61. (mapcat! #(map inc %) ! [[1 2 3 4] [20 10]])! ! ;; [2 3 4 5 21 11]
  • 62. (map inc! (mapcat identity! [[1 2 3 4] [20 10]])! )! ! ;; [2 3 4 5 21 11]
  • 63. (->>! [[1 2 3 4] [20 10]]! (mapcat identity)! (map inc))! ! ;; [2 3 4 5 21 11]
  • 64. Travel Log • Forest of Higher Order • Reduce • Map • Filter • City of Mapcat • City of Zip • The Emerald City of FP
  • 65.
  • 66. –- L. Frank Baum, The Wonderful Wizard of Oz “Even with eyes protected by the green spectacles, Dorothy and her friends were at first dazzled by the brilliancy of the wonderful City.”
  • 67. Zip • Map (Clojure) • Zip (C#) • ZipWith (Haskell)
  • 69. 1 2 3 Add 10 20 30 11 22 33
  • 70. new[] {1, 2, 3}! .Zip(! new[] {10, 20, 30},! (x, y) => x + y);! ! // { 11, 22, 33 }
  • 71. (map + ! [1 2 3] [10 20 30])! ! ;; [11 22 33]
  • 72. 1 2 Add 10 20 30 11 22 ???
  • 73. new[] {1, 2}! .Zip(! new[] {10, 20, 30},! (x, y) => x + y);! ! // { 11, 22 }
  • 74. (map + ! [1 2] [10 20 30])! ! ;; [11 22]
  • 75. 1 2 3 Add 10 20 11 22 ???
  • 76. new[] {1, 2, 3}! .Zip(! new[] {10, 20},! (x, y) => x + y);! ! // { 11, 22 }
  • 77. (map + ! [1 2 3] [10 20])! ! ;; [11 22]
  • 78. FizzBuzz Kata 1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13 14 FizzBuzz 16 17 Fizz 19 Buzz Fizz 22 23 Fizz Buzz 26 Fizz 28 29 FizzBuzz 31
  • 79. var inf = Enumerable.Range(0, int.MaxValue);! var fizzes = inf.Select(x => x%3 == 0 ? “Fizz” : “”);! var buzzes = inf.Select(x => x%5 == 0 ? “Buzz” : “”);! var numbers = inf.Select(x => x.ToString());! ! var fizzbuzzer = ! fizzes! .Zip(buzzes, (f, b) => f + b)! .Zip(numbers, (fb, n) => fb == “” ? n : fb);! ! fizzbuzzer.Skip(33).First();! // “Fizz”! ! fizzbuzzer.Skip(55).First();! // “Buzz”! ! fizzbuzzer.Skip(150).First();! // “FizzBuzz”! ! fizzbuzzer.Skip(2).First();! // “2”
  • 80. var inf = Enumerable! .Range(0, int.MaxValue);! ! var fizzes = inf.Select(! x => x%3 == 0 ? “Fizz” : “”);! var buzzes = inf.Select(! x => x%5 == 0 ? “Buzz” : “”);! ! var numbers = inf.Select(! x => x.ToString());
  • 81. var fizzbuzzer = ! fizzes! .Zip(buzzes,(f, b) => f + b)! .Zip(numbers,! (fb, n) => fb == “” ? n : fb);
  • 83. var inf = Enumerable.Range(0, int.MaxValue);! var fizzes = inf.Select(x => x%3 == 0 ? “Fizz” : “”);! var buzzes = inf.Select(x => x%5 == 0 ? “Buzz” : “”);! var numbers = inf.Select(x => x.ToString());! ! var fizzbuzzer = ! fizzes! .Zip(buzzes, (f, b) => f + b)! .Zip(numbers, (fb, n) => fb == “” ? n : fb);! ! fizzbuzzer.Skip(33).First();! // “Fizz”! ! fizzbuzzer.Skip(55).First();! // “Buzz”! ! fizzbuzzer.Skip(150).First();! // “FizzBuzz”! ! fizzbuzzer.Skip(2).First();! // “2”
  • 84. Travel Log • Forest of Higher Order • Reduce • Map • Filter • City of Mapcat • City of Zip • The Emerald City of FP
  • 85.
  • 86. –- L. Frank Baum, The Marvelous Land of Oz “To 'know Thyself' is considered quite an accomplishment.”
  • 88. ;; transducer signature! (whatever, input -> whatever) -> (whatever, input -> whatever) *from: http://clojure.org/transducers
  • 90. new[] {1, 2, 3, 4}! .Select(x => x+1); ! ! // { 2, 3, 4, 5 }
  • 91. new[] {1, 2, 3, 4}! .Aggregate(! new List<int>(),! (m, x) => {! m.Add(x+1);! return m;! }).ToArray();! ! // { 2, 3, 4, 5 }
  • 92. new[] {1, 2, 3, 4}! .Aggregate(! new List<int>(),! (m, x) => {! m.Add(x+1);! return m;! }).ToArray();! ! // { 2, 3, 4, 5 }
  • 93. new[] {1, 2, 3, 4}! .Aggregate(coll! new typeof(coll),! (m, x) => {! m.Step(x+1);! return m;! });! // { 2, 3, 4, 5 } FAKE C# CODE!!! FAKE C# CODE!!!
  • 95. ;; map
 (defn map [f coll]
 (reduce ! (fn [m x]! (conj m (f x)))! [] coll)) *from: http://youtu.be/6mTbuzafcII
  • 96. ;; map
 (defn map [f coll]
 (reduce ! (fn [m x]! (conj m (f x)))! [] coll)) *from: http://youtu.be/6mTbuzafcII
  • 97. ;; map
 (defn mapping [f]! (fn [step]! (fn [m x]! (step m (f x)))))! ! (defn map [f coll]! (reduce ! ((mapping f) conj) ! [] coll)) *from: http://youtu.be/6mTbuzafcII
  • 98. (defn mapping [f]! (fn [step]! (fn [m x]! (step m (f x))))) *from: http://youtu.be/6mTbuzafcII
  • 99. (defn map [f coll]! (reduce ! ((mapping f) conj) ! [] coll)) *from: http://youtu.be/6mTbuzafcII
  • 100. ;; map
 (defn map [f coll]
 (reduce ! (fn [m x]! (conj m (f x)))! [] coll)) *from: http://youtu.be/6mTbuzafcII
  • 101. ;; map
 (defn mapping [f]! (fn [step]! (fn [m x]! (step m (f x)))))! ! (defn map [f coll]! (reduce ! ((mapping f) conj) ! [] coll)) *from: http://youtu.be/6mTbuzafcII
  • 102. –- L. Frank Baum, The Marvelous Land of Oz “[A]lthough I feel that I know a tremendous lot, I am not yet aware how much there is in the world to find out about. It will take me a little time to discover whether I am very wise or very foolish.”
  • 104. –- L. Frank Baum, The Marvelous Land of Oz “Everything has to come to an end, sometime.”
  • 105. Bibliography (conference sessions) • Rich Hickey - Transducers
 Strange Loop 2014
 https://www.youtube.com/watch?v=6mTbuzafcII • Rich Hickey - Inside Transducers + more.async
 Clojure Conj 2014
 https://www.youtube.com/watch?v=4KqUvG8HPYo
  • 106. Bibliography (blog posts) • Martin Fowler - Collection Pipelines
 http://martinfowler.com/articles/collection-pipeline/ • Justin Etheredge - A Visual Look at the LINQ SelectMany Operator
 http://www.codethinked.com/a-visual-look-at-the-linq- selectmany-operator
  • 107. Bibliography (white papers) • Graham Hutton - A Tutorial on the Universality and Expressiveness of fold
 http://www.cs.nott.ac.uk/~gmh/fold.pdf
  • 108. Bibliography (websites) • Sam Allen - Dot Net Perls
 http://www.dotnetperls.com/ • lots of smart people - ClojureDocs
 https://clojuredocs.org/ • Rich Hickey - Transducers
 http://clojure.org/transducers
  • 109. Bibliography (Pluralsight classes) • Scott Allen - LINQ Architecture
 http://www.pluralsight.com/courses/linq-architecture • Deborah Kurata - Practical LINQ
 http://www.pluralsight.com/courses/practical-linq
  • 110. Bibliography (books) • Michael Fogus and Chris Houser - The Joy of Clojure
 http://www.manning.com/fogus2/
  • 111. Images • [1] The International Wizard of Oz Club, http://ozclub.org/ • [3-5, 7] Wikipedia, public domain • [9] W.W. Denslow - The Wonderful Wizard of Oz • [47] Flicker - Jeremy Schultz, https://www.flickr.com/photos/ tao_zhyn/442965594/ • [51] W.W. Denslow - The Marvelous Land of Oz • [65, 85] W.W. Denslow - The Wonderful Wizard of Oz • [103] Me taken at dinner by my wife while at Strange Loop 2014