Programming in handstand
PHP Meetup, 2014. 04. 23.
Programming in handstand
Attila Magyar (@athoshun)
http://athoshun.eu
2/149
Programming in handstand
Attila Magyar (@athoshun)
http://athoshun.eu
http://balabit.com
3/149
Programming in handstand
Attila Magyar (@athoshun)
http://athoshun.eu
http://balabit.com
Rafael Ördög (@devillsroom)
http:...
Programming in handstand
Attila Magyar (@athoshun)
http://athoshun.eu
http://balabit.com
Rafael Ördög (@devillsroom)
http:...
Programming in handstand
Attila Magyar (@athoshun)
http://athoshun.eu
http://balabit.com
Rafael Ördög (@devillsroom)
http:...
FizzBuzz

Write a program that iterates through the
numbers from 1 to 100 and:

For multiples of 3 print "Fizz"

For mu...
FizzBuzz

Write a program that iterates through the
numbers from 1 to 100 and:

For multiples of 3 print "Fizz"

For mu...
FizzBuzz
for ($i = 0; $i < 100; ++$i) {
if ($i % 3 === 0) {
print "Fizz";
}
if ($i % 5 === 0) {
print "Buzz";
}
if ($i % 3...
FizzBuzz
for ($i = 0; $i < 100; ++$i) {
if ($i % 3 === 0) {
print "Fizz";
}
if ($i % 5 === 0) {
print "Buzz";
}
if ($i % 3...
FizzBuzz
function fizzbuzz()
{
$sequence = array();
for ($i = 0; $i < 100; ++$i) {
$formatted = "";
if ($i % 3 === 0) {
$f...
FizzBuzz
function fizzbuzz()
{
$sequence = array();
for ($i = 0; $i < 100; ++$i) {
$formatted = "";
if ($i % 3 === 0) {
$f...
FizzBuzz
function fizzbuzz()
{
$sequence = array();
for ($i = 1; $i < 101; ++$i) {
$formatted = "";
if ($i % 3 === 0) {
$f...
FizzBuzz
function fizzbuzz()
{
$sequence = array();
for ($i = 1; $i < 101; ++$i) {
$formatted = "";
if ($i % 3 === 0) {
$f...
FizzBuzz
function fizzbuzz()
{
$sequence = array();
for ($i = 1; $i < 101; ++$i) {
$formatted = "";
if ($i % 3 === 0) {
$f...
FizzBuzzBeep
function fizzbuzz()
{
$sequence = array();
for ($i = 1; $i < 101; ++$i) {
$formatted = "";
if ($i % 3 === 0) ...
FizzBuzzBeep
function fizzbuzz($with_beep = false)
{
$sequence = array();
for ($i = 1; $i < 101; ++$i) {
$formatted = "";
...
FizzBuzzBeep
function fizzbuzz($with_beep = false, $with_digits = false)
{
$sequence = array();
for ($i = 1; $i < 101; ++$...
FizzBuzzBeep
function fizzbuzz($with_beep = false, $with_digits = false)
{
$sequence = array();
for ($i = 1; $i < 101; ++$...
No loops!
20/149
No loops!
21/149
No loops!
function fizzbuzz()
{
$sequence = array();
for ($i = 1; $i < 101; ++$i) {
$formatted = "";
if ($i % 3 === 0) {
$...
No loops!
function fizzbuzz($i = 1, array $result = array())
{
if ($i > 100)
return $result;
$formatted = "";
if ($i % 3 =...
No loops!
function fizzbuzz($i = 1, array $result = array())
{
if ($i > 100)
return $result;
$formatted = "";
if ($i % 3 =...
No loops!
function fizzbuzz()
{
$sequence = array();
for ($i = 1; $i < 101; ++$i) {
$formatted = "";
if ($i % 3 === 0) {
$...
array_map($callable, $array)
function fizzbuzz()
{
$sequence = array();
for ($i = 1; $i < 101; ++$i) {
$formatted = "";
if...
No loops!
function fizzbuzz()
{
$sequence = array();
for ($i = 1; $i < 101; ++$i) {
$formatted = "";
if ($i % 3 === 0) {
$...
No loops!
function fizzbuzz()
{
return array_map(
function ($i) {
$formatted = "";
if ($i % 3 === 0) {
$formatted .= "Fizz...
No loops!
function fizzbuzz()
{
return array_map(
function ($i) {
$formatted = "";
if ($i % 3 === 0) {
$formatted .= "Fizz...
Still complex, rigid
function fizzbuzz($with_beep = false, $with_digits = false)
{
return array_map(
function ($i) use ($w...
No conditional statements!
function fizzbuzz()
{
return array_map(
function ($i) {
$formatted = "";
if ($i % 3 === 0) {
$f...
Create some duplication
function fizzbuzz()
{
return array_map(
function ($i) {
$formatted = "";
if ($i % 3 === 0) {
$form...
Create some duplication
function fizzbuzz()
{
return array_map(
function ($i) {
$formatted = "";
if ($i % 3 === 0) {
$form...
Uniformize
function fizzbuzz()
{
return array_map(
function ($i) {
$formatted = "";
if ($i % 3 === 0) {
$formatted .= "Fiz...
Scalar vector→
function fizzbuzz()
{
return array_map(
function ($i) {
$formatted = "";
if ($i % 3 === 0) {
$formatted .= ...
Scalar vector→
function fizzbuzz()
{
return array_map(
function ($i) {
$formatted = array();
if ($i % 3 === 0) {
$formatte...
Extract condition
function fizzbuzz()
{
return array_map(
function ($i) {
$formatted = array();
if ($i % 3 === 0) {
$forma...
Extract condition
function fizzbuzz()
{
return array_map(
function ($i) {
$formatted = array();
$condition = $i % 3 === 0;...
Extract representation
function fizzbuzz()
{
return array_map(
function ($i) {
$formatted = array();
$condition = $i % 3 =...
Extract representation
function fizzbuzz()
{
return array_map(
function ($i) {
$formatted = array();
$condition = $i % 3 =...
Eliminate duplication
function fizzbuzz()
{
return array_map(
function ($i) {
$formatted = array();
$condition = $i % 3 ==...
Eliminate duplication
function fizzbuzz()
{
return array_map(
function ($i) {
$formatted = array();
$condition = $i % 3 ==...
Eliminate duplication
function fizzbuzz()
{
return array_map(
function ($i) {
$formatted = array();
$rules = array(array($...
array_filter($array, $callable)
function fizzbuzz()
{
return array_map(
function ($i) {
$formatted = array();
$rules = arr...
Eliminate conditional
function fizzbuzz()
{
return array_map(
function ($i) {
$formatted = array();
$rules = array(array($...
Eliminate conditional
function fizzbuzz()
{
return array_map(
function ($i) {
$formatted = array();
$rules = array_filter(...
Remove some noise
function fizzbuzz()
{
return array_map(
function ($i) {
$formatted = array();
$rules = array_filter(
arr...
Remove some noise
function fizzbuzz()
{
return array_map(
function ($i) {
$formatted = array();
$rules = array_filter(
arr...
Remove some noise
function fizzbuzz()
{
return array_map(
function ($i) {
$formatted = array();
$rules = array_filter(
arr...
Zoom in
function fizzbuzz()
{
return array_map(
function ($i) {
$formatted = array();
$rules = array_filter(
array(array($...
Zoom in
$formatted = array();
$rules = array_filter(
array(
array($i % 3 === 0, "Fizz"),
array($i % 5 === 0, "Buzz"),
),
f...
$formatted $rules→
$formatted = array();
$rules = array_filter(
array(
array($i % 3 === 0, "Fizz"),
array($i % 5 === 0, "B...
$formatted $rules→
$formatted = array();
$rules = array_filter(
array(
array($i % 3 === 0, "Fizz"),
array($i % 5 === 0, "B...
Uniformize
$formatted = array();
$rules = array_filter(
array(
array($i % 3 === 0, "Fizz"),
array($i % 5 === 0, "Buzz"),
)...
Uniformize
$formatted = array();
$rules = array_filter(
array(
array($i % 3 === 0, "Fizz"),
array($i % 5 === 0, "Buzz"),
)...
$formatted $rules→
$formatted = array();
$rules = array_filter(
array(
array($i % 3 === 0, "Fizz"),
array($i % 5 === 0, "B...
$formatted $rules→
$formatted = array();
$rules = array_filter(
array(
array($i % 3 === 0, "Fizz"),
array($i % 5 === 0, "B...
$formatted $rules→
$formatted = array();
$rules = array_filter(
array(
array($i % 3 === 0, "Fizz"),
array($i % 5 === 0, "B...
$formatted $rules→
$formatted = array();
$rules = array_filter(
array(
array($i % 3 === 0, "Fizz"),
array($i % 5 === 0, "B...
Remove some redundancy
$formatted = array();
$rules = array_filter(
array(
array($i % 3 === 0, "Fizz"),
array($i % 5 === 0...
Remove some redundancy
$formatted = array();
$rules = array_filter(
array(
array($i % 3 === 0, "Fizz"),
array($i % 5 === 0...
array_pad($array, $size, $value)
$formatted = array();
$rules = array_filter(
array(
array($i % 3 === 0, "Fizz"),
array($i...
array_pad(array(1, 2), 5, 42);
// array(1, 2, 42, 42, 42)
array_pad(array(1, 2), 1, 42);
// array(1, 2)
Padding
$formatted...
Padding
$formatted = array();
$rules = array_filter(
array(
array($i % 3 === 0, "Fizz"),
array($i % 5 === 0, "Buzz"),
),
f...
Padding
$formatted = array();
$rules = array_pad(array_filter(
array(
array($i % 3 === 0, "Fizz"),
array($i % 5 === 0, "Bu...
Padding
$formatted = array();
$rules = array_pad(
array_filter(
array(
array($i % 3 === 0, "Fizz"),
array($i % 5 === 0, "B...
foreach array_map()→
$formatted = array();
$rules = array_pad(
array_filter(
array(
array($i % 3 === 0, "Fizz"),
array($i ...
foreach array_map()→
$formatted = array_map(function(array $rule){return $rule[1];},
array_pad(
array_filter(
array(
array...
foreach array_map→
$formatted = array_map(
function (array $rule) { return $rule[1]; },
array_pad(
array_filter(
array(
ar...
inline implode
$formatted = array_map(
function (array $rule) { return $rule[1]; },
array_pad(
array_filter(
array(
array(...
inline implode
return implode(array_map(
function (array $rule) { return $rule[1]; },
array_pad(
array_filter(
array(
arra...
inline implode
return implode(
array_map(
function (array $rule) { return $rule[1]; },
array_pad(
array_filter(
array(
arr...
Eliminate unneeded values
return implode(
array_map(
function (array $rule) { return $rule[1]; },
array_pad(
array_filter(...
array_pad() array_map()↔
return implode(
array_map(
function (array $rule) { return $rule[1]; },
array_pad(
array_filter(
...
array_pad() array_map()↔
return implode(
array_pad(
array_map(
function (array $rule) { return $rule[1]; },
array_filter(
...
array_map() for_all()→
return implode(
array_pad(
array_map(
function (array $rule) { return $rule[1]; },
array_filter(
ar...
array_map() for_all()→
return implode(
array_pad(
array_map(
function (array $rule) { return $rule[1]; },
array_filter(
ar...
array_map() for_all()→
return implode(
array_pad(
array_map(
function (array $rule) { return $rule[1]; },
array_filter(
ar...
array_map() for_all()→
return implode(
array_pad(
array_map(
function (array $rule) { return $rule[1]; },
array_filter(
ar...
array_map() for_all()→
return implode(
array_pad(
array_map(
function (array $rule) { return $rule[1]; },
array_filter(
ar...
array_map() for_all()→
return implode(
array_pad(
array_map(
function (array $rule) { return $rule[1]; },
array_filter(
ar...
array_map() for_all()→
return implode(
array_pad(
array_map(
function (array $rule) { return $rule[1]; },
array_filter(
ar...
array_map() for_all()→
function for_all(array $items, $action)
{
return array_map($action, $items);
}
return implode(
arra...
array_filter matching_rules→
function for_all(array $items, $action)
{
return array_map($action, $items);
}
return implode...
array_filter matching_rules→
function matching_rules(array $rules) {
return array_filter(
$rules,
function (array $rule) {...
For all matching rules...
function matching_rules(array $rules) {
return array_filter(
$rules,
function (array $rule) { re...
select representation
return implode(
array_pad(
for_all(
matching_rules(
array(
array($i % 3 === 0, "Fizz"),
array($i % 5...
select representation
$select_representation = function (array $rule)
{
return $rule[1];
};
return implode(
array_pad(
for...
select representation
function select_representation()
{
return function (array $rule) { return $rule[1]; };
}
return impl...
array_pad() either_or_else()→
function select_representation()
{
return function (array $rule) { return $rule[1]; };
}
ret...
array_pad() either_or_else()→
function either_or_else(array $either, $or_else)
{
return array_pad($either, 1, $or_else);
}...
implode() concat()→
function either_or_else(array $either, $or_else)
{
return array_pad($either, 1, $or_else);
}
return im...
implode() concat()→
function concat(array $parts)
{
return implode($parts);
}
return concat(
either_or_else(
for_all(
matc...
Parametric rules: conditions
function concat(array $parts)
{
return implode($parts);
}
return concat(
either_or_else(
for_...
Parametric rules: conditions
function matching_rules(array $rules) {
return array_filter(
$rules,
function (array $rule) {...
Parametric rules: conditions
function matching_rules($n, array $rules) {
return array_filter(
$rules,
function (array $rul...
Remove duplication
function matching_rules($n, array $rules) {
return array_filter(
$rules,
function (array $rule) use ($n...
Remove duplication
function is_multiple_of($divisor) {
return function ($n) use ($divisor) {
return $n % $divisor === 0; }...
Parametric representation
function is_multiple_of($divisor) {
return function ($n) use ($divisor) {
return $n % $divisor =...
Parametric representation
return concat(
either_or_else(
for_all(
matching_rules(
$i,
array(
array(is_multiple_of(3),
func...
Parametric representation
return concat(for_all(
either_or_else(
for_all(
matching_rules(
$i,
array(
array(is_multiple_of(...
Parametric representation
return concat(
for_all(
either_or_else(
for_all(
matching_rules(
$i,
array(array(is_multiple_of(...
Parametric action
function select_representation() {
return function (array $rule) { return $rule[1]; };
}
return concat(
...
Parametric action
function select_action() {
return function (array $rule) { return $rule[1]; };
}
return concat(
for_all(...
Parametric action
function select_action() {
return function (array $rule) { return $rule[1]; };
}
return concat(
for_all(...
Parametric action
return concat(
for_all(
either_or_else(
for_all(
matching_rules(
$i,
array(array(is_multiple_of(3),
func...
Parametric action
function apply_with($n) {
return function ($f) use ($n) { return $f($n); };
}
return concat(
for_all(
ei...
Parametric action
function apply_with($n) {
return function ($f) use ($n) { return $f($n); };
}
return concat(
for_all(
ei...
Remove duplication
return concat(
for_all(
either_or_else(
for_all(
matching_rules(
$i,
array(array(is_multiple_of(3),
fun...
Remove duplication
function const_fn($const) {
return function ($n) use ($const) { return $const; };
}
return concat(
for_...
Name things
function const_fn($const) {
return function ($n) use ($const) { return $const; };
}
return concat(
for_all(
ei...
Name things
function to_string() {
return function ($n) { return "$n"; };
}
return concat(
for_all(
either_or_else(
for_al...
Encapsulation
function to_string() {
return function ($n) { return "$n"; };
}
return concat(
for_all(
either_or_else(
for_...
Encapsulation
function when($condition, $action) {
return array($condition, $action);
}
return concat(
for_all(
either_or_...
When ... then ...
function when($condition, $action) {
return array($condition, $action);
}
return concat(
for_all(
either...
When ... then ...
function then($action) {
return $action;
}
return concat(
for_all(
either_or_else(
for_all(
matching_rul...
Extract ugly details
function then($action) {
return $action;
}
return concat(
for_all(
either_or_else(
for_all(
matching_...
Extract ugly details
function apply_rules($n, array $rules, $otherwise_fn)
{
return concat(
for_all(
either_or_else(
for_a...
Extract ugly details
function apply_rules($n, array $rules, $otherwise_fn)
{
return concat(
for_all(
either_or_else(
for_a...
Extract ugly details
function fizzbuzz()
{
return for_all(
range(1, 100),
function ($i) {
apply_rules(
$i,
array(
when(is_...
Extract ugly details
function fizzbuzz()
{
return for_all(
range(1, 100),
function ($i) {
apply_rules(
$i,
array(
when(is_...
Extract ugly details
function apply_rules(array $rules, $otherwise_fn) {
return function ($n) use ($rules, $otherwise_fn) ...
Readability refinements
function apply_rules(array $rules, $otherwise_fn) {
return function ($n) use ($rules, $otherwise_f...
Readability refinements
function otherwise($action) {
return $action;
}
function fizzbuzz()
{
return for_all(
range(1, 100...
Readability refinements
function otherwise($action) {
return $action;
}
function fizzbuzz()
{
return for_all(
range(1, 100...
Readability refinements
function otherwise($action) {
return $action;
}
function fizzbuzz()
{
return for_all(
range(1, 100...
Extract, extract, extract
function fizzbuzz()
{
return for_all(
range(1, 100),
apply_rules(
array(
when(is_multiple_of(3),...
Extract, extract, extract
function format_numbers(array $rules) {
return for_all(range(1, 100),
apply_rules($rules,
otherw...
The resulting algorithm
function format_numbers(array $rules)
{
return for_all(range(1, 100),
apply_rules($rules,
otherwis...
The resulting algorithm
function format_numbers(array $rules)
{
return for_all(range(1, 100),
apply_rules($rules,
otherwis...
The resulting algorithm
function format_numbers(array $rules)
{
return for_all(range(1, 100),
apply_rules($rules,
otherwis...
The resulting algorithm
function format_numbers(array $rules)
{
return for_all(range(1, 100),
apply_rules($rules,
otherwis...
The resulting algorithm
function format_numbers(array $rules)
{
return for_all(range(1, 100),
apply_rules($rules,
otherwis...
SOLID: Open/Closed Principle
function format_numbers(array $rules)
{
return for_all(range(1, 100),
apply_rules($rules,
oth...
SOLID: Open/Closed Principle
function format_numbers(array $rules)
{
return for_all(range(1, 100),
apply_rules($rules,
oth...
SOLID: Open/Closed Principle
function format_numbers(array $rules)
{
return for_all(range(1, 100),
apply_rules($rules,
oth...
SOLID: What about the others?
function format_numbers(array $rules)
{
return for_all(
range(1, 100),
apply_rules(
$rules,
...
SOLID: Single Responsibility
function format_numbers(array $rules)
{
return for_all(
range(1, 100),
apply_rules(
$rules,
o...
SOLID: Single Responsibility ✓
function format_numbers(array $rules)
{
return for_all(
range(1, 100),
apply_rules(
$rules,...
SOLID: Liskov Substitution
function format_numbers(array $rules)
{
return for_all(
range(1, 100),
apply_rules(
$rules,
oth...
SOLID: Liskov Substitution ✓
function format_numbers(array $rules)
{
return for_all(
range(1, 100),
apply_rules(
$rules,
o...
SOLID: Interface Segregation
function format_numbers(array $rules)
{
return for_all(
range(1, 100),
apply_rules(
$rules,
o...
SOLID: Interface Segregation ✓
function format_numbers(array $rules)
{
return for_all(
range(1, 100),
apply_rules(
$rules,...
SOLID: Dependency Inversion
function format_numbers(array $rules)
{
return for_all(
range(1, 100),
apply_rules(
$rules,
ot...
SOLID: Dependency Inversion ✓
function format_numbers(array $rules)
{
return for_all(
range(1, 100),
apply_rules(
$rules,
...
Wait a sec: isn't SOLID for OOP?
146/149
Wait a sec: isn't SOLID for OOP?

If you have OO, you can have FP:

Iterator Lazy evaluation→

Iterator, Command Map, F...
Get out of your comfort zone

And extend your mental toolbox!
Thank you!
Upcoming SlideShare
Loading in...5
×

Programming in handstand

790

Published on

An example demonstrating how to have fun while learning new concepts in the art of software development.

0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
790
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
2
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Programming in handstand

  1. 1. Programming in handstand PHP Meetup, 2014. 04. 23.
  2. 2. Programming in handstand Attila Magyar (@athoshun) http://athoshun.eu 2/149
  3. 3. Programming in handstand Attila Magyar (@athoshun) http://athoshun.eu http://balabit.com 3/149
  4. 4. Programming in handstand Attila Magyar (@athoshun) http://athoshun.eu http://balabit.com Rafael Ördög (@devillsroom) http://c0de-x.com http://leanpoker.org 4/149
  5. 5. Programming in handstand Attila Magyar (@athoshun) http://athoshun.eu http://balabit.com Rafael Ördög (@devillsroom) http://c0de-x.com http://leanpoker.org http://coderetreat.org http://www.meetup.com/Coderetreat-Budapest/ 5/149
  6. 6. Programming in handstand Attila Magyar (@athoshun) http://athoshun.eu http://balabit.com Rafael Ördög (@devillsroom) http://c0de-x.com http://leanpoker.org http://coderetreat.org http://www.meetup.com/Coderetreat-Budapest/ Gergely Nagy (@algernoone) http://asylum.madhouse-project.org/ http://syslog-ng.org/ 6/149
  7. 7. FizzBuzz  Write a program that iterates through the numbers from 1 to 100 and:  For multiples of 3 print "Fizz"  For multiples of 5 print "Buzz"  For numbers which are multiples of both 3 and 5 print "FizzBuzz"  For others, print the number itself 7/149
  8. 8. FizzBuzz  Write a program that iterates through the numbers from 1 to 100 and:  For multiples of 3 print "Fizz"  For multiples of 5 print "Buzz"  For numbers which are multiples of both 3 and 5 print "FizzBuzz"  For others, print the number itself 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, ... 8/149
  9. 9. FizzBuzz for ($i = 0; $i < 100; ++$i) { if ($i % 3 === 0) { print "Fizz"; } if ($i % 5 === 0) { print "Buzz"; } if ($i % 3 !== 0 && $i % 5 !== 0) { print $i; } print ", "; } 9/149
  10. 10. FizzBuzz for ($i = 0; $i < 100; ++$i) { if ($i % 3 === 0) { print "Fizz"; } if ($i % 5 === 0) { print "Buzz"; } if ($i % 3 !== 0 && $i % 5 !== 0) { print $i; } print ", "; } 10/149
  11. 11. FizzBuzz function fizzbuzz() { $sequence = array(); for ($i = 0; $i < 100; ++$i) { $formatted = ""; if ($i % 3 === 0) { $formatted .= "Fizz"; } if ($i % 5 === 0) { $formatted .= "Buzz"; } if ($i % 3 !== 0 && $i % 5 !== 0) { $formatted = "$i"; } $sequence[] = $formatted; } return $sequence; } 11/149
  12. 12. FizzBuzz function fizzbuzz() { $sequence = array(); for ($i = 0; $i < 100; ++$i) { $formatted = ""; if ($i % 3 === 0) { $formatted .= "Fizz"; } if ($i % 5 === 0) { $formatted .= "Buzz"; } if ($i % 3 !== 0 && $i % 5 !== 0) { $formatted = "$i"; } $sequence[] = $formatted; } return $sequence; } 12/149
  13. 13. FizzBuzz function fizzbuzz() { $sequence = array(); for ($i = 1; $i < 101; ++$i) { $formatted = ""; if ($i % 3 === 0) { $formatted .= "Fizz"; } if ($i % 5 === 0) { $formatted .= "Buzz"; } if ($i % 3 !== 0 && $i % 5 !== 0) { $formatted = "$i"; } $sequence[] = $formatted; } return $sequence; } 13/149
  14. 14. FizzBuzz function fizzbuzz() { $sequence = array(); for ($i = 1; $i < 101; ++$i) { $formatted = ""; if ($i % 3 === 0) { $formatted .= "Fizz"; } if ($i % 5 === 0) { $formatted .= "Buzz"; } if ($i % 3 !== 0 && $i % 5 !== 0) { $formatted = "$i"; } $sequence[] = $formatted; } return $sequence; } 14/149
  15. 15. FizzBuzz function fizzbuzz() { $sequence = array(); for ($i = 1; $i < 101; ++$i) { $formatted = ""; if ($i % 3 === 0) { $formatted .= "Fizz"; } if ($i % 5 === 0) { $formatted .= "Buzz"; } if ($formatted === "") { $formatted = "$i"; } $sequence[] = $formatted; } return $sequence; } 15/149
  16. 16. FizzBuzzBeep function fizzbuzz() { $sequence = array(); for ($i = 1; $i < 101; ++$i) { $formatted = ""; if ($i % 3 === 0) { $formatted .= "Fizz"; } if ($i % 5 === 0) { $formatted .= "Buzz"; } if ($formatted === "") { $formatted = "$i"; } $sequence[] = $formatted; } return $sequence; } 16/149
  17. 17. FizzBuzzBeep function fizzbuzz($with_beep = false) { $sequence = array(); for ($i = 1; $i < 101; ++$i) { $formatted = ""; if ($i % 3 === 0) $formatted .= "Fizz"; if ($i % 5 === 0) $formatted .= "Buzz"; if ($with_beep && $i % 7 === 0) $formatted .= "Beep"; if ($formatted === "") { $formatted = "$i"; } $sequence[] = $formatted; } return $sequence; } 17/149
  18. 18. FizzBuzzBeep function fizzbuzz($with_beep = false, $with_digits = false) { $sequence = array(); for ($i = 1; $i < 101; ++$i) { $formatted = ""; if ($i % 3 === 0 || ($with_digits && strpos...)) $formatted .= "Fizz"; if ($i % 5 === 0 || ($with_digits && strpos...)) $formatted .= "Buzz"; if ($with_beep && $i % 7 === 0 || ($with_digits ...)) $formatted .= "Beep"; if ($formatted === "") { $formatted = "$i"; } $sequence[] = $formatted; } return $sequence; } 18/149
  19. 19. FizzBuzzBeep function fizzbuzz($with_beep = false, $with_digits = false) { $sequence = array(); for ($i = 1; $i < 101; ++$i) { $formatted = ""; if ($i % 3 === 0 || ($with_digits && strpos...)) $formatted .= "Fizz"; if ($i % 5 === 0 || ($with_digits && strpos...)) $formatted .= "Buzz"; if ($with_beep && $i % 7 === 0 || ($with_digits ...)) $formatted .= "Beep"; if ($formatted === "") { $formatted = "$i"; } $sequence[] = $formatted; } return $sequence; } 19/149
  20. 20. No loops! 20/149
  21. 21. No loops! 21/149
  22. 22. No loops! function fizzbuzz() { $sequence = array(); for ($i = 1; $i < 101; ++$i) { $formatted = ""; if ($i % 3 === 0) { $formatted .= "Fizz"; } if ($i % 5 === 0) { $formatted .= "Buzz"; } if ($formatted === "") { $formatted = "$i"; } $sequence[] = $formatted; } return $sequence; } 22/149
  23. 23. No loops! function fizzbuzz($i = 1, array $result = array()) { if ($i > 100) return $result; $formatted = ""; if ($i % 3 === 0) { $formatted .= "Fizz"; } if ($i % 5 === 0) { $formatted .= "Buzz"; } if ($formatted === "") { $formatted .= "$i"; } return fizzbuzz( $i + 1, array_merge($result, array($formatted)) ); } 23/149
  24. 24. No loops! function fizzbuzz($i = 1, array $result = array()) { if ($i > 100) return $result; $formatted = ""; if ($i % 3 === 0) { $formatted .= "Fizz"; } if ($i % 5 === 0) { $formatted .= "Buzz"; } if ($formatted === "") { $formatted .= "$i"; } return fizzbuzz( $i + 1, array_merge($result, array($formatted)) ); } PHP Fatal error:  Maximum function nesting level of '100' Reached, aborting! 24/149
  25. 25. No loops! function fizzbuzz() { $sequence = array(); for ($i = 1; $i < 101; ++$i) { $formatted = ""; if ($i % 3 === 0) { $formatted .= "Fizz"; } if ($i % 5 === 0) { $formatted .= "Buzz"; } if ($formatted === "") { $formatted = "$i"; } $sequence[] = $formatted; } return $sequence; } 25/149
  26. 26. array_map($callable, $array) function fizzbuzz() { $sequence = array(); for ($i = 1; $i < 101; ++$i) { $formatted = ""; if ($i % 3 === 0) { $formatted .= "Fizz"; } if ($i % 5 === 0) { $formatted .= "Buzz"; } if ($formatted === "") { $formatted = "$i"; } $sequence[] = $formatted; } return $sequence; } array_map( function ($x) { return 2*$x; }, array(1, 2, 3) ); // array(2, 4, 6) 26/149
  27. 27. No loops! function fizzbuzz() { $sequence = array(); for ($i = 1; $i < 101; ++$i) { $formatted = ""; if ($i % 3 === 0) { $formatted .= "Fizz"; } if ($i % 5 === 0) { $formatted .= "Buzz"; } if ($formatted === "") { $formatted = "$i"; } $sequence[] = $formatted; } return $sequence; } array_map( function ($x) { return 2*$x; }, array(1, 2, 3) ); // array(2, 4, 6) 27/149
  28. 28. No loops! function fizzbuzz() { return array_map( function ($i) { $formatted = ""; if ($i % 3 === 0) { $formatted .= "Fizz"; } if ($i % 5 === 0) { $formatted .= "Buzz"; } if ($formatted === "") { $formatted = "$i"; } return $formatted; }, range(1, 100) ); } array_map( function ($x) { return 2*$x; }, array(1, 2, 3) ); // array(2, 4, 6) 28/149
  29. 29. No loops! function fizzbuzz() { return array_map( function ($i) { $formatted = ""; if ($i % 3 === 0) { $formatted .= "Fizz"; } if ($i % 5 === 0) { $formatted .= "Buzz"; } if ($formatted === "") { $formatted = "$i"; } return $formatted; }, range(1, 100) ); } 29/149
  30. 30. Still complex, rigid function fizzbuzz($with_beep = false, $with_digits = false) { return array_map( function ($i) use ($with_beep, $with_digits) { $formatted = ""; if ($i % 3 === 0 || ($with_digits && strpos...)) $formatted .= "Fizz"; if ($i % 5 === 0 || ($with_digits && strpos...)) $formatted .= "Buzz"; if ($with_beep && (...)) $formatted .= "Buzz"; if ($formatted === "") $formatted = "$i"; return $formatted; }, range(1, 100) ); } 30/149
  31. 31. No conditional statements! function fizzbuzz() { return array_map( function ($i) { $formatted = ""; if ($i % 3 === 0) { $formatted .= "Fizz"; } if ($i % 5 === 0) { $formatted .= "Buzz"; } if ($formatted === "") { $formatted = "$i"; } return $formatted; }, range(1, 100) ); } 31/149
  32. 32. Create some duplication function fizzbuzz() { return array_map( function ($i) { $formatted = ""; if ($i % 3 === 0) { $formatted .= "Fizz"; } if ($i % 5 === 0) { $formatted .= "Buzz"; } if ($formatted === "") { $formatted = "$i"; } return $formatted; }, range(1, 100) ); } 32/149
  33. 33. Create some duplication function fizzbuzz() { return array_map( function ($i) { $formatted = ""; if ($i % 3 === 0) { $formatted .= "Fizz"; } if ($i % 5 === 0) { $formatted .= "Buzz"; } if ($formatted === "") { $formatted = "$i"; } return $formatted; }, range(1, 100) ); } 33/149
  34. 34. Uniformize function fizzbuzz() { return array_map( function ($i) { $formatted = ""; if ($i % 3 === 0) { $formatted .= "Fizz"; } if ($i % 5 === 0) { $formatted .= "Buzz"; } if ($formatted === "") { $formatted .= "$i"; } return $formatted; }, range(1, 100) ); } 34/149
  35. 35. Scalar vector→ function fizzbuzz() { return array_map( function ($i) { $formatted = ""; if ($i % 3 === 0) { $formatted .= "Fizz"; } if ($i % 5 === 0) { $formatted .= "Buzz"; } if ($formatted === "") { $formatted .= "$i"; } return $formatted; }, range(1, 100) ); } 35/149
  36. 36. Scalar vector→ function fizzbuzz() { return array_map( function ($i) { $formatted = array(); if ($i % 3 === 0) { $formatted[] = "Fizz"; } if ($i % 5 === 0) { $formatted[] = "Buzz"; } if (count($formatted) === 0) { $formatted[] = "$i"; } return implode($formatted); }, range(1, 100) ); } 36/149
  37. 37. Extract condition function fizzbuzz() { return array_map( function ($i) { $formatted = array(); if ($i % 3 === 0) { $formatted[] = "Fizz"; } if ($i % 5 === 0) { $formatted[] = "Buzz"; } if (count($formatted) === 0) { $formatted[] = "$i"; } return implode($formatted); }, range(1, 100) ); } 37/149
  38. 38. Extract condition function fizzbuzz() { return array_map( function ($i) { $formatted = array(); $condition = $i % 3 === 0; if ($condition) { $formatted[] = "Fizz"; } $condition = $i % 5 === 0; if ($condition) { $formatted[] = "Buzz"; } $condition = count($formatted) === 0; if ($condition) { $formatted[] = "$i"; } return implode($formatted); }, range(1, 100) ); } 38/149
  39. 39. Extract representation function fizzbuzz() { return array_map( function ($i) { $formatted = array(); $condition = $i % 3 === 0; if ($condition) { $formatted[] = "Fizz"; } $condition = $i % 5 === 0; if ($condition) { $formatted[] = "Buzz"; } $condition = count($formatted) === 0; if ($condition) { $formatted[] = "$i"; } return implode($formatted); }, range(1, 100) ); } 39/149
  40. 40. Extract representation function fizzbuzz() { return array_map( function ($i) { $formatted = array(); $condition = $i % 3 === 0; $representation = "Fizz"; if ($condition) $formatted[] = $representation; $condition = $i % 5 === 0; $representation = "Buzz"; if ($condition) $formatted[] = $representation; $condition = count($formatted) === 0; $representation = "$i"; if ($condition) $formatted[] = $representation; return implode($formatted); }, range(1, 100) ); } 40/149
  41. 41. Eliminate duplication function fizzbuzz() { return array_map( function ($i) { $formatted = array(); $condition = $i % 3 === 0; $representation = "Fizz"; if ($condition) $formatted[] = $representation; $condition = $i % 5 === 0; $representation = "Buzz"; if ($condition) $formatted[] = $representation; $condition = count($formatted) === 0; $representation = "$i"; if ($condition) $formatted[] = $representation; return implode($formatted); }, range(1, 100) ); } 41/149
  42. 42. Eliminate duplication function fizzbuzz() { return array_map( function ($i) { $formatted = array(); $condition = $i % 3 === 0; $representation = "Fizz"; if ($condition) $formatted[] = $representation; $condition = $i % 5 === 0; $representation = "Buzz"; if ($condition) $formatted[] = $representation; $condition = count($formatted) === 0; $representation = "$i"; if ($condition) $formatted[] = $representation; return implode($formatted); }, range(1, 100) ); } 42/149
  43. 43. Eliminate duplication function fizzbuzz() { return array_map( function ($i) { $formatted = array(); $rules = array(array($i % 3 === 0, "Fizz"), array($i % 5 === 0, "Buzz")); foreach ($rules as $rule) { list($condition, $representation) = $rule; if ($condition) $formatted[] = $representation; } $condition = count($formatted) === 0; $representation = "$i"; if ($condition) $formatted[] = $representation; return implode($formatted); }, range(1, 100) ); } 43/149
  44. 44. array_filter($array, $callable) function fizzbuzz() { return array_map( function ($i) { $formatted = array(); $rules = array(array($i % 3 === 0, "Fizz"), array($i % 5 === 0, "Buzz")); foreach ($rules as $rule) { list($condition, $representation) = $rule; if ($condition) $formatted[] = $representation; } $condition = count($formatted) === 0; $representation = "$i"; if ($condition) $formatted[] = $representation; return implode($formatted); }, range(1, 100) ); } array_filter(array(1, 2, 3, 4), function ($x) { return $x > 2; }); // array(3, 4) 44/149
  45. 45. Eliminate conditional function fizzbuzz() { return array_map( function ($i) { $formatted = array(); $rules = array(array($i % 3 === 0, "Fizz"), array($i % 5 === 0, "Buzz")); foreach ($rules as $rule) { list($condition, $representation) = $rule; if ($condition) $formatted[] = $representation; } $condition = count($formatted) === 0; $representation = "$i"; if ($condition) $formatted[] = $representation; return implode($formatted); }, range(1, 100) ); } 45/149
  46. 46. Eliminate conditional function fizzbuzz() { return array_map( function ($i) { $formatted = array(); $rules = array_filter( array(array($i % 3 === 0, "Fizz"), array($i % 5 === 0, "Buzz")), function (array $rule) { return $rule[0]; }); foreach ($rules as $rule) { list($condition, $representation) = $rule; $formatted[] = $representation; } $condition = count($formatted) === 0; $representation = "$i"; if ($condition) $formatted[] = $representation; return implode($formatted); }, range(1, 100) ); } 46/149
  47. 47. Remove some noise function fizzbuzz() { return array_map( function ($i) { $formatted = array(); $rules = array_filter( array(array($i % 3 === 0, "Fizz"), array($i % 5 === 0, "Buzz")), function (array $rule) { return $rule[0]; }); foreach ($rules as $rule) { list($condition, $representation) = $rule; $formatted[] = $representation; } $condition = count($formatted) === 0; $representation = "$i"; if ($condition) $formatted[] = $representation; return implode($formatted); }, range(1, 100) ); } 47/149
  48. 48. Remove some noise function fizzbuzz() { return array_map( function ($i) { $formatted = array(); $rules = array_filter( array(array($i % 3 === 0, "Fizz"), array($i % 5 === 0, "Buzz")), function (array $rule) { return $rule[0]; }); foreach ($rules as $rule) { $formatted[] = $rule[1]; } $condition = count($formatted) === 0; $representation = "$i"; if ($condition) $formatted[] = $representation; return implode($formatted); }, range(1, 100) ); } 48/149
  49. 49. Remove some noise function fizzbuzz() { return array_map( function ($i) { $formatted = array(); $rules = array_filter( array(array($i % 3 === 0, "Fizz"), array($i % 5 === 0, "Buzz")), function (array $rule) { return $rule[0]; }); foreach ($rules as $rule) { $formatted[] = $rule[1]; } $condition = count($formatted) === 0; $representation = "$i"; if ($condition) $formatted[] = $representation; return implode($formatted); }, range(1, 100) ); } 49/149
  50. 50. Zoom in function fizzbuzz() { return array_map( function ($i) { $formatted = array(); $rules = array_filter( array(array($i % 3 === 0, "Fizz"), array($i % 5 === 0, "Buzz")), function (array $rule) { return $rule[0]; }); foreach ($rules as $rule) { $formatted[] = $rule[1]; } $condition = count($formatted) === 0; $representation = "$i"; if ($condition) $formatted[] = $representation; return implode($formatted); }, range(1, 100) ); } 50/149
  51. 51. Zoom in $formatted = array(); $rules = array_filter( array( array($i % 3 === 0, "Fizz"), array($i % 5 === 0, "Buzz"), ), function (array $rule) { return $rule[0]; } ); foreach ($rules as $rule) { $formatted[] = $rule[1]; } $condition = count($formatted) === 0; $representation = "$i"; if ($condition) { $formatted[] = $representation; } return implode($formatted); 51/149
  52. 52. $formatted $rules→ $formatted = array(); $rules = array_filter( array( array($i % 3 === 0, "Fizz"), array($i % 5 === 0, "Buzz"), ), function (array $rule) { return $rule[0]; } ); foreach ($rules as $rule) { $formatted[] = $rule[1]; } $condition = count($formatted) === 0; $representation = "$i"; if ($condition) { $formatted[] = $representation; } return implode($formatted); 52/149
  53. 53. $formatted $rules→ $formatted = array(); $rules = array_filter( array( array($i % 3 === 0, "Fizz"), array($i % 5 === 0, "Buzz"), ), function (array $rule) { return $rule[0]; } ); foreach ($rules as $rule) { $formatted[] = $rule[1]; } $condition = count($rules) === 0; $representation = "$i"; if ($condition) { $formatted[] = $representation; } return implode($formatted); 53/149
  54. 54. Uniformize $formatted = array(); $rules = array_filter( array( array($i % 3 === 0, "Fizz"), array($i % 5 === 0, "Buzz"), ), function (array $rule) { return $rule[0]; } ); foreach ($rules as $rule) { $formatted[] = $rule[1]; } $condition = count($rules) === 0; $representation = "$i"; if ($condition) { $formatted[] = $representation; } return implode($formatted); 54/149
  55. 55. Uniformize $formatted = array(); $rules = array_filter( array( array($i % 3 === 0, "Fizz"), array($i % 5 === 0, "Buzz"), ), function (array $rule) { return $rule[0]; } ); foreach ($rules as $rule) { $formatted[] = $rule[1]; } $rule = array(count($rules) === 0, "$i"); if ($rule[0]) { $formatted[] = $rule[1]; } return implode($formatted); 55/149
  56. 56. $formatted $rules→ $formatted = array(); $rules = array_filter( array( array($i % 3 === 0, "Fizz"), array($i % 5 === 0, "Buzz"), ), function (array $rule) { return $rule[0]; } ); foreach ($rules as $rule) { $formatted[] = $rule[1]; } $rule = array(count($rules) === 0, "$i"); if ($rule[0]) { $formatted[] = $rule[1]; } return implode($formatted); 56/149
  57. 57. $formatted $rules→ $formatted = array(); $rules = array_filter( array( array($i % 3 === 0, "Fizz"), array($i % 5 === 0, "Buzz"), ), function (array $rule) { return $rule[0]; } ); foreach ($rules as $rule) { $formatted[] = $rule[1]; } if (count($rules) === 0) { $rules[] = array(count($rules) === 0, "$i"); } return implode($formatted); 57/149
  58. 58. $formatted $rules→ $formatted = array(); $rules = array_filter( array( array($i % 3 === 0, "Fizz"), array($i % 5 === 0, "Buzz"), ), function (array $rule) { return $rule[0]; } ); foreach ($rules as $rule) { $formatted[] = $rule[1]; } if (count($rules) === 0) { $rules[] = array(count($rules) === 0, "$i"); } return implode($formatted); 58/149
  59. 59. $formatted $rules→ $formatted = array(); $rules = array_filter( array( array($i % 3 === 0, "Fizz"), array($i % 5 === 0, "Buzz"), ), function (array $rule) { return $rule[0]; } ); if (count($rules) === 0) { $rules[] = array(count($rules) === 0, "$i"); } foreach ($rules as $rule) { $formatted[] = $rule[1]; } return implode($formatted); 59/149
  60. 60. Remove some redundancy $formatted = array(); $rules = array_filter( array( array($i % 3 === 0, "Fizz"), array($i % 5 === 0, "Buzz"), ), function (array $rule) { return $rule[0]; } ); if (count($rules) === 0) { $rules[] = array(count($rules) === 0, "$i"); } foreach ($rules as $rule) { $formatted[] = $rule[1]; } return implode($formatted); 60/149
  61. 61. Remove some redundancy $formatted = array(); $rules = array_filter( array( array($i % 3 === 0, "Fizz"), array($i % 5 === 0, "Buzz"), ), function (array $rule) { return $rule[0]; } ); if (count($rules) === 0) { $rules[] = array(true, "$i"); } foreach ($rules as $rule) { $formatted[] = $rule[1]; } return implode($formatted); 61/149
  62. 62. array_pad($array, $size, $value) $formatted = array(); $rules = array_filter( array( array($i % 3 === 0, "Fizz"), array($i % 5 === 0, "Buzz"), ), function (array $rule) { return $rule[0]; } ); if (count($rules) === 0) { $rules[] = array(true, "$i"); } foreach ($rules as $rule) { $formatted[] = $rule[1]; } return implode($formatted); array_pad(array(1, 2), 5, 42); // array(1, 2, 42, 42, 42) array_pad(array(1, 2), 1, 42); // array(1, 2) 62/149
  63. 63. array_pad(array(1, 2), 5, 42); // array(1, 2, 42, 42, 42) array_pad(array(1, 2), 1, 42); // array(1, 2) Padding $formatted = array(); $rules = array_filter( array( array($i % 3 === 0, "Fizz"), array($i % 5 === 0, "Buzz"), ), function (array $rule) { return $rule[0]; } ); if (count($rules) === 0) { $rules[] = array(true, "$i"); } foreach ($rules as $rule) { $formatted[] = $rule[1]; } return implode($formatted); 63/149
  64. 64. Padding $formatted = array(); $rules = array_filter( array( array($i % 3 === 0, "Fizz"), array($i % 5 === 0, "Buzz"), ), function (array $rule) { return $rule[0]; } ); if (count($rules) === 0) { $rules[] = array(true, "$i"); } foreach ($rules as $rule) { $formatted[] = $rule[1]; } return implode($formatted); 64/149
  65. 65. Padding $formatted = array(); $rules = array_pad(array_filter( array( array($i % 3 === 0, "Fizz"), array($i % 5 === 0, "Buzz"), ), function (array $rule) { return $rule[0]; } ), 1, array(true, "$i") ); foreach ($rules as $rule) { $formatted[] = $rule[1]; } return implode($formatted); 65/149
  66. 66. Padding $formatted = array(); $rules = array_pad( array_filter( array( array($i % 3 === 0, "Fizz"), array($i % 5 === 0, "Buzz"), ), function (array $rule) { return $rule[0]; } ), 1, array(true, "$i") ); foreach ($rules as $rule) { $formatted[] = $rule[1]; } return implode($formatted); 66/149
  67. 67. foreach array_map()→ $formatted = array(); $rules = array_pad( array_filter( array( array($i % 3 === 0, "Fizz"), array($i % 5 === 0, "Buzz"), ), function (array $rule) { return $rule[0]; } ), 1, array(true, "$i") ); foreach ($rules as $rule) { $formatted[] = $rule[1]; } return implode($formatted); 67/149
  68. 68. foreach array_map()→ $formatted = array_map(function(array $rule){return $rule[1];}, array_pad( array_filter( array( array($i % 3 === 0, "Fizz"), array($i % 5 === 0, "Buzz"), ), function (array $rule) { return $rule[0]; } ), 1, array(true, "$i") )); return implode($formatted); 68/149
  69. 69. foreach array_map→ $formatted = array_map( function (array $rule) { return $rule[1]; }, array_pad( array_filter( array( array($i % 3 === 0, "Fizz"), array($i % 5 === 0, "Buzz"), ), function (array $rule) { return $rule[0]; } ), 1, array(true, "$i") ) ); return implode($formatted); 69/149
  70. 70. inline implode $formatted = array_map( function (array $rule) { return $rule[1]; }, array_pad( array_filter( array( array($i % 3 === 0, "Fizz"), array($i % 5 === 0, "Buzz"), ), function (array $rule) { return $rule[0]; } ), 1, array(true, "$i") ) ); return implode($formatted); 70/149
  71. 71. inline implode return implode(array_map( function (array $rule) { return $rule[1]; }, array_pad( array_filter( array( array($i % 3 === 0, "Fizz"), array($i % 5 === 0, "Buzz"), ), function (array $rule) { return $rule[0]; } ), 1, array(true, "$i") ) )); 71/149
  72. 72. inline implode return implode( array_map( function (array $rule) { return $rule[1]; }, array_pad( array_filter( array( array($i % 3 === 0, "Fizz"), array($i % 5 === 0, "Buzz"), ), function (array $rule) { return $rule[0]; } ), 1, array(true, "$i") ) ) ); 72/149
  73. 73. Eliminate unneeded values return implode( array_map( function (array $rule) { return $rule[1]; }, array_pad( array_filter( array( array($i % 3 === 0, "Fizz"), array($i % 5 === 0, "Buzz"), ), function (array $rule) { return $rule[0]; } ), 1, array(true, "$i") ) ) ); 73/149
  74. 74. array_pad() array_map()↔ return implode( array_map( function (array $rule) { return $rule[1]; }, array_pad( array_filter( array( array($i % 3 === 0, "Fizz"), array($i % 5 === 0, "Buzz"), ), function (array $rule) { return $rule[0]; } ), 1, array(true, "$i") ) ) ); 74/149
  75. 75. array_pad() array_map()↔ return implode( array_pad( array_map( function (array $rule) { return $rule[1]; }, array_filter( array( array($i % 3 === 0, "Fizz"), array($i % 5 === 0, "Buzz"), ), function (array $rule) { return $rule[0]; } ) ), 1, "$i" ) ); 75/149
  76. 76. array_map() for_all()→ return implode( array_pad( array_map( function (array $rule) { return $rule[1]; }, array_filter( array( array($i % 3 === 0, "Fizz"), array($i % 5 === 0, "Buzz"), ), function (array $rule) { return $rule[0]; } ) ), 1, "$i" ) ); 76/149
  77. 77. array_map() for_all()→ return implode( array_pad( array_map( function (array $rule) { return $rule[1]; }, array_filter( array( array($i % 3 === 0, "Fizz"), array($i % 5 === 0, "Buzz"), ), function (array $rule) { return $rule[0]; } ) ), 1, "$i" ) ); 77/149
  78. 78. array_map() for_all()→ return implode( array_pad( array_map( function (array $rule) { return $rule[1]; }, array_filter( array( array($i % 3 === 0, "Fizz"), array($i % 5 === 0, "Buzz"), ), function (array $rule) { return $rule[0]; } ) ), 1, "$i" ) ); 78/149
  79. 79. array_map() for_all()→ return implode( array_pad( array_map( function (array $rule) { return $rule[1]; }, array_filter( array( array($i % 3 === 0, "Fizz"), array($i % 5 === 0, "Buzz"), ), function (array $rule) { return $rule[0]; } ) ), 1, "$i" ) ); 79/149
  80. 80. array_map() for_all()→ return implode( array_pad( array_map( function (array $rule) { return $rule[1]; }, array_filter( array( array($i % 3 === 0, "Fizz"), array($i % 5 === 0, "Buzz"), ), function (array $rule) { return $rule[0]; } ) ), 1, "$i" ) ); 80/149
  81. 81. array_map() for_all()→ return implode( array_pad( array_map( function (array $rule) { return $rule[1]; }, array_filter( array( array($i % 3 === 0, "Fizz"), array($i % 5 === 0, "Buzz"), ), function (array $rule) { return $rule[0]; } ) ), 1, "$i" ) ); 81/149
  82. 82. array_map() for_all()→ return implode( array_pad( array_map( function (array $rule) { return $rule[1]; }, array_filter( array( array($i % 3 === 0, "Fizz"), array($i % 5 === 0, "Buzz"), ), function (array $rule) { return $rule[0]; } ) ), 1, "$i" ) ); 82/149
  83. 83. array_map() for_all()→ function for_all(array $items, $action) { return array_map($action, $items); } return implode( array_pad( for_all( array_filter( array( array($i % 3 === 0, "Fizz"), array($i % 5 === 0, "Buzz"), ), function (array $rule) { return $rule[0]; } ), function (array $rule) { return $rule[1]; } ), 1, "$i" ) ); 83/149
  84. 84. array_filter matching_rules→ function for_all(array $items, $action) { return array_map($action, $items); } return implode( array_pad( for_all( array_filter( array( array($i % 3 === 0, "Fizz"), array($i % 5 === 0, "Buzz"), ), function (array $rule) { return $rule[0]; } ), function (array $rule) { return $rule[1]; } ), 1, "$i" ) ); 84/149
  85. 85. array_filter matching_rules→ function matching_rules(array $rules) { return array_filter( $rules, function (array $rule) { return $rule[0]; }); } return implode( array_pad( for_all( matching_rules( array( array($i % 3 === 0, "Fizz"), array($i % 5 === 0, "Buzz"), ) ), function (array $rule) { return $rule[1]; } ), 1, "$i" ) ); 85/149
  86. 86. For all matching rules... function matching_rules(array $rules) { return array_filter( $rules, function (array $rule) { return $rule[0]; }); } return implode( array_pad( for_all( matching_rules( array( array($i % 3 === 0, "Fizz"), array($i % 5 === 0, "Buzz"), ) ), function (array $rule) { return $rule[1]; } ), 1, "$i" ) ); 86/149
  87. 87. select representation return implode( array_pad( for_all( matching_rules( array( array($i % 3 === 0, "Fizz"), array($i % 5 === 0, "Buzz"), ) ), function (array $rule) { return $rule[1]; } ), 1, "$i" ) ); 87/149
  88. 88. select representation $select_representation = function (array $rule) { return $rule[1]; }; return implode( array_pad( for_all( matching_rules( array( array($i % 3 === 0, "Fizz"), array($i % 5 === 0, "Buzz"), ) ), $select_representation ), 1, "$i" ) ); 88/149
  89. 89. select representation function select_representation() { return function (array $rule) { return $rule[1]; }; } return implode( array_pad( for_all( matching_rules( array( array($i % 3 === 0, "Fizz"), array($i % 5 === 0, "Buzz"), ) ), select_representation() ), 1, "$i" ) ); 89/149
  90. 90. array_pad() either_or_else()→ function select_representation() { return function (array $rule) { return $rule[1]; }; } return implode( array_pad( for_all( matching_rules( array( array($i % 3 === 0, "Fizz"), array($i % 5 === 0, "Buzz"), ) ), select_representation() ), 1, "$i" ) ); 90/149
  91. 91. array_pad() either_or_else()→ function either_or_else(array $either, $or_else) { return array_pad($either, 1, $or_else); } return implode( either_or_else( for_all( matching_rules( array( array($i % 3 === 0, "Fizz"), array($i % 5 === 0, "Buzz"), ) ), select_representation() ), "$i" ) ); 91/149
  92. 92. implode() concat()→ function either_or_else(array $either, $or_else) { return array_pad($either, 1, $or_else); } return implode( either_or_else( for_all( matching_rules( array( array($i % 3 === 0, "Fizz"), array($i % 5 === 0, "Buzz"), ) ), select_representation() ), "$i" ) ); 92/149
  93. 93. implode() concat()→ function concat(array $parts) { return implode($parts); } return concat( either_or_else( for_all( matching_rules( array( array($i % 3 === 0, "Fizz"), array($i % 5 === 0, "Buzz"), ) ), select_representation() ), "$i" ) ); 93/149
  94. 94. Parametric rules: conditions function concat(array $parts) { return implode($parts); } return concat( either_or_else( for_all( matching_rules( array( array($i % 3 === 0, "Fizz"), array($i % 5 === 0, "Buzz"), ) ), select_representation() ), "$i" ) ); 94/149
  95. 95. Parametric rules: conditions function matching_rules(array $rules) { return array_filter( $rules, function (array $rule) { return $rule[0]; }); } return concat( either_or_else( for_all( matching_rules( array( array($i % 3 === 0, "Fizz"), array($i % 5 === 0, "Buzz"), ) ), select_representation() ), "$i" ) ); 95/149
  96. 96. Parametric rules: conditions function matching_rules($n, array $rules) { return array_filter( $rules, function (array $rule) use ($n) {return $rule[0]($n);});} return concat( either_or_else( for_all( matching_rules( $i, array( array(function ($n) { return $n%3 === 0; }, "Fizz"), array(function ($n) { return $n%5 === 0; }, "Buzz"), ) ), select_representation() ), "$i" ) ); 96/149
  97. 97. Remove duplication function matching_rules($n, array $rules) { return array_filter( $rules, function (array $rule) use ($n) {return $rule[0]($n);});} return concat( either_or_else( for_all( matching_rules( $i, array( array(function ($n) { return $n%3 === 0; }, "Fizz"), array(function ($n) { return $n%5 === 0; }, "Buzz"), ) ), select_representation() ), "$i" ) ); 97/149
  98. 98. Remove duplication function is_multiple_of($divisor) { return function ($n) use ($divisor) { return $n % $divisor === 0; }; } return concat( either_or_else( for_all( matching_rules( $i, array( array(is_multiple_of(3), "Fizz"), array(is_multiple_of(5), "Buzz"), ) ), select_representation() ), "$i" ) ); 98/149
  99. 99. Parametric representation function is_multiple_of($divisor) { return function ($n) use ($divisor) { return $n % $divisor === 0; }; } return concat( either_or_else( for_all( matching_rules( $i, array( array(is_multiple_of(3), "Fizz"), array(is_multiple_of(5), "Buzz"), ) ), select_representation() ), "$i" ) ); 99/149
  100. 100. Parametric representation return concat( either_or_else( for_all( matching_rules( $i, array( array(is_multiple_of(3), function ($n) { return "Fizz"; }), array(is_multiple_of(5), function ($n) { return "Buzz"; }), ) ), select_representation() ), function ($n) { return "$n"; } ) ); 100/149
  101. 101. Parametric representation return concat(for_all( either_or_else( for_all( matching_rules( $i, array( array(is_multiple_of(3), function ($n) { return "Fizz"; }), array(is_multiple_of(5), function ($n) { return "Buzz"; }), ) ), select_representation() ), function ($n) { return "$n"; } ), function ($f) use ($i) { return $f($i); } )); 101/149
  102. 102. Parametric representation return concat( for_all( either_or_else( for_all( matching_rules( $i, array(array(is_multiple_of(3), function ($n){return "Fizz";}), array(is_multiple_of(5), function ($n){return "Buzz";}),) ), select_representation() ), function ($n) { return "$n"; } ), function ($f) use ($i) { return $f($i); } ) ); 102/149
  103. 103. Parametric action function select_representation() { return function (array $rule) { return $rule[1]; }; } return concat( for_all( either_or_else( for_all( matching_rules( $i, array(array(is_multiple_of(3), function ($n){return "Fizz";}), array(is_multiple_of(5), function ($n){return "Buzz";}),) ), select_representation() ), function ($n) { return "$n"; } ), function ($f) use ($i) { return $f($i); } ) ); 103/149
  104. 104. Parametric action function select_action() { return function (array $rule) { return $rule[1]; }; } return concat( for_all( either_or_else( for_all( matching_rules( $i, array(array(is_multiple_of(3), function ($n){return "Fizz";}), array(is_multiple_of(5), function ($n){return "Buzz";}),) ), select_action() ), function ($n) { return "$n"; } ), function ($f) use ($i) { return $f($i); } ) ); 104/149
  105. 105. Parametric action function select_action() { return function (array $rule) { return $rule[1]; }; } return concat( for_all( either_or_else( for_all( matching_rules( $i, array(array(is_multiple_of(3), function ($n){return "Fizz";}), array(is_multiple_of(5), function ($n){return "Buzz";}),) ), select_action() ), function ($n) { return "$n"; } ), function ($f) use ($i) { return $f($i); } ) ); 105/149
  106. 106. Parametric action return concat( for_all( either_or_else( for_all( matching_rules( $i, array(array(is_multiple_of(3), function ($n){return "Fizz";}), array(is_multiple_of(5), function ($n){return "Buzz";}),) ), select_action() ), function ($n) { return "$n"; } ), function ($f) use ($i) { return $f($i); } ) ); 106/149
  107. 107. Parametric action function apply_with($n) { return function ($f) use ($n) { return $f($n); }; } return concat( for_all( either_or_else( for_all( matching_rules( $i, array(array(is_multiple_of(3), function ($n){return "Fizz";}), array(is_multiple_of(5), function ($n){return "Buzz";}),) ), select_action() ), function ($n) { return "$n"; } ), apply_with($i) ) ); 107/149
  108. 108. Parametric action function apply_with($n) { return function ($f) use ($n) { return $f($n); }; } return concat( for_all( either_or_else( for_all( matching_rules( $i, array(array(is_multiple_of(3), function ($n){return "Fizz";}), array(is_multiple_of(5), function ($n){return "Buzz";}),) ), select_action() ), function ($n) { return "$n"; } ), apply_with($i) ) ); 108/149
  109. 109. Remove duplication return concat( for_all( either_or_else( for_all( matching_rules( $i, array(array(is_multiple_of(3), function ($n){return "Fizz";}), array(is_multiple_of(5), function ($n){return "Buzz";}),) ), select_action() ), function ($n) { return "$n"; } ), apply_with($i) ) ); 109/149
  110. 110. Remove duplication function const_fn($const) { return function ($n) use ($const) { return $const; }; } return concat( for_all( either_or_else( for_all( matching_rules( $i, array(array(is_multiple_of(3), const_fn("Fizz")), array(is_multiple_of(5), const_fn("Buzz")),) ), select_action() ), function ($n) { return "$n"; } ), apply_with($i) ) ); 110/149
  111. 111. Name things function const_fn($const) { return function ($n) use ($const) { return $const; }; } return concat( for_all( either_or_else( for_all( matching_rules( $i, array(array(is_multiple_of(3), const_fn("Fizz")), array(is_multiple_of(5), const_fn("Buzz")),) ), select_action() ), function ($n) { return "$n"; } ), apply_with($i) ) ); 111/149
  112. 112. Name things function to_string() { return function ($n) { return "$n"; }; } return concat( for_all( either_or_else( for_all( matching_rules( $i, array(array(is_multiple_of(3), const_fn("Fizz")), array(is_multiple_of(5), const_fn("Buzz")),) ), select_action() ), to_string() ), apply_with($i) ) ); 112/149
  113. 113. Encapsulation function to_string() { return function ($n) { return "$n"; }; } return concat( for_all( either_or_else( for_all( matching_rules( $i, array(array(is_multiple_of(3), const_fn("Fizz")), array(is_multiple_of(5), const_fn("Buzz")),) ), select_action() ), to_string() ), apply_with($i) ) ); 113/149
  114. 114. Encapsulation function when($condition, $action) { return array($condition, $action); } return concat( for_all( either_or_else( for_all( matching_rules( $i, array(when( is_multiple_of(3), const_fn("Fizz")), when( is_multiple_of(5), const_fn("Buzz")),) ), select_action() ), to_string() ), apply_with($i) ) ); 114/149
  115. 115. When ... then ... function when($condition, $action) { return array($condition, $action); } return concat( for_all( either_or_else( for_all( matching_rules( $i, array(when( is_multiple_of(3), const_fn("Fizz")), when( is_multiple_of(5), const_fn("Buzz")),) ), select_action() ), to_string() ), apply_with($i) ) ); 115/149
  116. 116. When ... then ... function then($action) { return $action; } return concat( for_all( either_or_else( for_all( matching_rules( $i, array(when( is_multiple_of(3), then(const_fn("Fizz"))), when( is_multiple_of(5), then(const_fn("Buzz"))),) ), select_action() ), to_string() ), apply_with($i) ) ); 116/149
  117. 117. Extract ugly details function then($action) { return $action; } return concat( for_all( either_or_else( for_all( matching_rules( $i, array(when( is_multiple_of(3), then(const_fn("Fizz"))), when( is_multiple_of(5), then(const_fn("Buzz"))),) ), select_action() ), to_string() ), apply_with($i) ) ); 117/149
  118. 118. Extract ugly details function apply_rules($n, array $rules, $otherwise_fn) { return concat( for_all( either_or_else( for_all(matching_rules($n, $rules), select_action()), $otherwise_fn ), apply_with($n) ) ); } return apply_rules( $i, array( when(is_multiple_of(3), then(const_fn("Fizz"))), when(is_multiple_of(5), then(const_fn("Buzz"))), ), to_string() ); 118/149
  119. 119. Extract ugly details function apply_rules($n, array $rules, $otherwise_fn) { return concat( for_all( either_or_else( for_all(matching_rules($n, $rules), select_action()), $otherwise_fn ), apply_with($n) ) ); } return apply_rules( $i, array( when(is_multiple_of(3), then(const_fn("Fizz"))), when(is_multiple_of(5), then(const_fn("Buzz"))), ), to_string() ); 119/149
  120. 120. Extract ugly details function fizzbuzz() { return for_all( range(1, 100), function ($i) { apply_rules( $i, array( when(is_multiple_of(3), then(const_fn("Fizz"))), when(is_multiple_of(5), then(const_fn("Buzz"))), ), to_string() ) } ); } 120/149
  121. 121. Extract ugly details function fizzbuzz() { return for_all( range(1, 100), function ($i) { apply_rules( $i, array( when(is_multiple_of(3), then(const_fn("Fizz"))), when(is_multiple_of(5), then(const_fn("Buzz"))), ), to_string() ) } ); } 121/149
  122. 122. Extract ugly details function apply_rules(array $rules, $otherwise_fn) { return function ($n) use ($rules, $otherwise_fn) { return concat(for_all( ... )); }; } function fizzbuzz() { return for_all( range(1, 100), apply_rules( array( when(is_multiple_of(3), then(const_fn("Fizz"))), when(is_multiple_of(5), then(const_fn("Buzz"))), ), to_string() ) ); } 122/149
  123. 123. Readability refinements function apply_rules(array $rules, $otherwise_fn) { return function ($n) use ($rules, $otherwise_fn) { return concat(for_all( ... )); }; } function fizzbuzz() { return for_all( range(1, 100), apply_rules( array( when(is_multiple_of(3), then(const_fn("Fizz"))), when(is_multiple_of(5), then(const_fn("Buzz"))), ), to_string() ) ); } 123/149
  124. 124. Readability refinements function otherwise($action) { return $action; } function fizzbuzz() { return for_all( range(1, 100), apply_rules( array( when(is_multiple_of(3), then(const_fn("Fizz"))), when(is_multiple_of(5), then(const_fn("Buzz"))), ), otherwise(to_string()) ) ); } 124/149
  125. 125. Readability refinements function otherwise($action) { return $action; } function fizzbuzz() { return for_all( range(1, 100), apply_rules( array( when(is_multiple_of(3), then(const_fn("Fizz"))), when(is_multiple_of(5), then(const_fn("Buzz"))), ), otherwise(to_string()) ) ); } 125/149
  126. 126. Readability refinements function otherwise($action) { return $action; } function fizzbuzz() { return for_all( range(1, 100), apply_rules( array( when(is_multiple_of(3), then(const_fn("Fizz"))), when(is_multiple_of(5), then(const_fn("Buzz"))), ), otherwise(convert_to_string()) ) ); } 126/149
  127. 127. Extract, extract, extract function fizzbuzz() { return for_all( range(1, 100), apply_rules( array( when(is_multiple_of(3), then(const_fn("Fizz"))), when(is_multiple_of(5), then(const_fn("Buzz"))), ), otherwise(convert_to_string()) ) ); } 127/149
  128. 128. Extract, extract, extract function format_numbers(array $rules) { return for_all(range(1, 100), apply_rules($rules, otherwise(convert_to_string())));} function fizzbuzz() { return array( when(is_multiple_of(3), then(const_fn("Fizz"))), when(is_multiple_of(5), then(const_fn("Buzz"))), ) ; } 128/149
  129. 129. The resulting algorithm function format_numbers(array $rules) { return for_all(range(1, 100), apply_rules($rules, otherwise(convert_to_string()))); } function fizzbuzz() { return array( when(is_multiple_of(3), then(const_fn("Fizz"))), when(is_multiple_of(5), then(const_fn("Buzz"))), ); } 129/149
  130. 130. The resulting algorithm function format_numbers(array $rules) { return for_all(range(1, 100), apply_rules($rules, otherwise(convert_to_string()))); } function fizzbuzz() { return array( when(is_multiple_of(3), then(const_fn("Fizz"))), when(is_multiple_of(5), then(const_fn("Buzz"))), ); } 130/149
  131. 131. The resulting algorithm function format_numbers(array $rules) { return for_all(range(1, 100), apply_rules($rules, otherwise(convert_to_string()))); } function fizzbuzz_rules() { return array( when(is_multiple_of(3), then(const_fn("Fizz"))), when(is_multiple_of(5), then(const_fn("Buzz"))), ); } function fizzbuzz() { return format_numbers(fizzbuzz_rules()); } 131/149
  132. 132. The resulting algorithm function format_numbers(array $rules) { return for_all(range(1, 100), apply_rules($rules, otherwise(convert_to_string()))); } function fizzbuzz_rules() { return array( when(is_multiple_of(3), then(const_fn("Fizz"))), when(is_multiple_of(5), then(const_fn("Buzz"))), ); } function fizzbuzz() { return format_numbers(fizzbuzz_rules()); } 132/149
  133. 133. The resulting algorithm function format_numbers(array $rules) { return for_all(range(1, 100), apply_rules($rules, otherwise(convert_to_string()))); } function fizzbuzz_rules() { return rules( when(is_multiple_of(3), then(const_fn("Fizz"))), when(is_multiple_of(5), then(const_fn("Buzz"))) ); } function fizzbuzz() { return format_numbers(fizzbuzz_rules()); } function rules() { return func_get_args(); } 133/149
  134. 134. SOLID: Open/Closed Principle function format_numbers(array $rules) { return for_all(range(1, 100), apply_rules($rules, otherwise(convert_to_string()))); } function fizzbuzz_rules() { return rules( when(is_multiple_of(3), then(const_fn("Fizz"))), when(is_multiple_of(5), then(const_fn("Buzz"))) ); } 134/149
  135. 135. SOLID: Open/Closed Principle function format_numbers(array $rules) { return for_all(range(1, 100), apply_rules($rules, otherwise(convert_to_string()))); } function fizzbuzz_rules() { return rules( when(is_multiple_of(3), then(const_fn("Fizz"))), when(is_multiple_of(5), then(const_fn("Buzz"))) ); } function fizzbuzzbeep_rules() { return append( fizzbuzz_rules(), when(is_multiple_of(7), then(const_fn("Beep"))) ); } 135/149
  136. 136. SOLID: Open/Closed Principle function format_numbers(array $rules) { return for_all(range(1, 100), apply_rules($rules, otherwise(convert_to_string()))); } function fizzbuzz_rules() { return rules( when(is_multiple_of(3), then(const_fn("Fizz"))), when(is_multiple_of(5), then(const_fn("Buzz"))) ); } function fizzbuzzbeep_rules() { return append( fizzbuzz_rules(), when(is_multiple_of(7), then(const_fn("Beep"))) ); } function append(array $array, $item) { ... } 136/149
  137. 137. SOLID: What about the others? function format_numbers(array $rules) { return for_all( range(1, 100), apply_rules( $rules, otherwise(convert_to_string()) ) ); } function fizzbuzz_rules() { return rules( when(is_multiple_of(3), then(const_fn("Fizz"))), when(is_multiple_of(5), then(const_fn("Buzz"))) ); } function fizzbuzz() { return format_numbers(fizzbuzz_rules()); } 137/149
  138. 138. SOLID: Single Responsibility function format_numbers(array $rules) { return for_all( range(1, 100), apply_rules( $rules, otherwise(convert_to_string()) ) ); } function fizzbuzz_rules() { return rules( when(is_multiple_of(3), then(const_fn("Fizz"))), when(is_multiple_of(5), then(const_fn("Buzz"))) ); } function fizzbuzz() { return format_numbers(fizzbuzz_rules()); } 138/149
  139. 139. SOLID: Single Responsibility ✓ function format_numbers(array $rules) { return for_all( range(1, 100), apply_rules( $rules, otherwise(convert_to_string()) ) ); } function fizzbuzz_rules() { return rules( when(is_multiple_of(3), then(const_fn("Fizz"))), when(is_multiple_of(5), then(const_fn("Buzz"))) ); } function fizzbuzz() { return format_numbers(fizzbuzz_rules()); } 139/149
  140. 140. SOLID: Liskov Substitution function format_numbers(array $rules) { return for_all( range(1, 100), apply_rules( $rules, otherwise(convert_to_string()) ) ); } function fizzbuzz_rules() { return rules( when(is_multiple_of(3), then(const_fn("Fizz"))), when(is_multiple_of(5), then(const_fn("Buzz"))) ); } function fizzbuzz() { return format_numbers(fizzbuzz_rules()); } 140/149
  141. 141. SOLID: Liskov Substitution ✓ function format_numbers(array $rules) { return for_all( range(1, 100), apply_rules( $rules, otherwise(convert_to_string()) ) ); } function fizzbuzz_rules() { return rules( when(is_multiple_of(3), then(const_fn("Fizz"))), when(is_multiple_of(5), then(const_fn("Buzz"))) ); } function fizzbuzz() { return format_numbers(fizzbuzz_rules()); } 141/149
  142. 142. SOLID: Interface Segregation function format_numbers(array $rules) { return for_all( range(1, 100), apply_rules( $rules, otherwise(convert_to_string()) ) ); } function fizzbuzz_rules() { return rules( when(is_multiple_of(3), then(const_fn("Fizz"))), when(is_multiple_of(5), then(const_fn("Buzz"))) ); } function fizzbuzz() { return format_numbers(fizzbuzz_rules()); } 142/149
  143. 143. SOLID: Interface Segregation ✓ function format_numbers(array $rules) { return for_all( range(1, 100), apply_rules( $rules, otherwise(convert_to_string()) ) ); } function fizzbuzz_rules() { return rules( when(is_multiple_of(3), then(const_fn("Fizz"))), when(is_multiple_of(5), then(const_fn("Buzz"))) ); } function fizzbuzz() { return format_numbers(fizzbuzz_rules()); } 143/149
  144. 144. SOLID: Dependency Inversion function format_numbers(array $rules) { return for_all( range(1, 100), apply_rules( $rules, otherwise(convert_to_string()) ) ); } function fizzbuzz_rules() { return rules( when(is_multiple_of(3), then(const_fn("Fizz"))), when(is_multiple_of(5), then(const_fn("Buzz"))) ); } function fizzbuzz() { return format_numbers(fizzbuzz_rules()); } 144/149
  145. 145. SOLID: Dependency Inversion ✓ function format_numbers(array $rules) { return for_all( range(1, 100), apply_rules( $rules, otherwise(convert_to_string()) ) ); } function fizzbuzz_rules() { return rules( when(is_multiple_of(3), then(const_fn("Fizz"))), when(is_multiple_of(5), then(const_fn("Buzz"))) ); } function fizzbuzz() { return format_numbers(fizzbuzz_rules()); } 145/149
  146. 146. Wait a sec: isn't SOLID for OOP? 146/149
  147. 147. Wait a sec: isn't SOLID for OOP?  If you have OO, you can have FP:  Iterator Lazy evaluation→  Iterator, Command Map, Filter→  Command, Factory High order functions→  Immutability  Composition Over Inheritance 147/149
  148. 148. Get out of your comfort zone  And extend your mental toolbox!
  149. 149. Thank you!
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×