SlideShare a Scribd company logo
1 of 67
Download to read offline
FUNCTIONAL
RUBY
ABOUT ME
• Mikhail Bortnyk
ABOUT ME
• Mikhail Bortnyk
• Too old for this shit
ABOUT ME
• Mikhail Bortnyk
• Too old for this shit
• Work for Amoniac OÜ
ABOUT ME
• Mikhail Bortnyk
• Too old for this shit
• Work for Amoniac OÜ
• Ruby developer
ABOUT ME
• Mikhail Bortnyk
• Too old for this shit
• Work for Amoniac OÜ
• Ruby developer
• Language researcher
ABOUT ME
• Mikhail Bortnyk
• Too old for this shit
• Work for Amoniac OÜ
• Ruby developer
• Language researcher
• kottans.org co-founder
ABOUT ME
• Mikhail Bortnyk
• Too old for this shit
• Work for Amoniac OÜ
• Ruby developer
• Language researcher
• kottans.org co-founder
• twitter @mikhailbortnyk
LOOK
FOR
JACKIE*
SPECIAL OFFER
*НАЕБЫВАЮ
PART ONE
WHY FUNCTIONAL?
SIDE EFFECTS
PROBLEM 1.1
• your objects store state
SIDE EFFECTS
PROBLEM 1.1
• your objects store state
• your code modifies state
SIDE EFFECTS
PROBLEM 1.1
• your objects store state
• your code modifies state
• your other code modifies state too
SIDE EFFECTS
PROBLEM 1.1
• your objects store state
• your code modifies state
• your other code modifies state too
• summary: mess
SIDE EFFECTS
PROBLEM 1.1
• your objects store state
• your code modifies state
• your other code modifies state too
• summary: mess
DATA/CODE ENTITY SHARING
PROBLEM 1.2
• your model stores both your logic and data
DATA/CODE ENTITY SHARING
PROBLEM 1.2
• your model stores both your logic and data
• nuff said
DATA/CODE ENTITY SHARING
PROBLEM 1.2
• your model stores both your logic and data
• nuff said
HYPE
PROBLEM 1.3
• Erlang
HYPE
PROBLEM 1.3
• Erlang
• Haskell
HYPE
PROBLEM 1.3
• Erlang
• Haskell
• Scala
HYPE
PROBLEM 1.3
• Erlang
• Haskell
• Scala
• OCaml
HYPE
PROBLEM 1.3
• Erlang
• Haskell
• Scala
• OCaml
• Lisp
HYPE
PROBLEM 1.3
• Erlang
• Haskell
• Scala
• OCaml
• Lisp
• Javascript (sic!)
HYPE
PROBLEM 1.3
• Erlang
• Haskell
• Scala
• OCaml
• Lisp
• Javascript (sic!)
• Ruby (sic!)
PART TWO
EASY (NOT REALLY) LEVEL
LIMITS ARE FREEING
CLEAN YOUR RUBY
• David Copeland article “Adventures in functional programming
with Ruby”
LIMITS ARE FREEING
CLEAN YOUR RUBY
• David Copeland article “Adventures in functional programming
with Ruby”
• Loops are just functions
LIMITS ARE FREEING
CLEAN YOUR RUBY
• David Copeland article “Adventures in functional programming
with Ruby”
• Loops are just functions
• Data structures are just functions
LIMITS ARE FREEING
CLEAN YOUR RUBY
• David Copeland article “Adventures in functional programming
with Ruby”
• Loops are just functions
• Data structures are just functions
• Objects are just functions
LIMITS ARE FREEING
CLEAN YOUR RUBY
• David Copeland article “Adventures in functional programming
with Ruby”
• Loops are just functions
• Data structures are just functions
• Objects are just functions
• Namespaces are just functions
LIMITS ARE FREEING
CLEAN YOUR RUBY
• David Copeland article “Adventures in functional programming
with Ruby”
• Loops are just functions
• Data structures are just functions
• Objects are just functions
• Namespaces are just functions
• P.S. Ruby HAS Tail Call Optimization
ROUGH HACK
TAIL-CALL OPTIMIZATION
def fact(n, acc=1)
return acc if n <= 1
fact(n-1, n*acc)
end
RubyVM::InstructionSequence.compile_option = {
tailcall_optimization: true,
trace_instruction: false
}
fact(1000)
FUNCTIONAL VS OBJECT-ORIENTED
SIDE TO SIDE COMPARISON
new_person = ->(name, birthdate, gender, title, id=nil) {
return ->(attribute) {
return id if attribute == :id
return name if attribute == :name
return birthdate if attribute == :birthdate
return gender if attribute == :gender
return title if attribute == :title
nil
}
}
class Person
attr_reader :id, :name, :birthdate, :gender, :title
def initialize(name, birthdate, gender, title, id=nil)
@id = id
@name = name
@birthdate = birthdate
@gender = gender
@title = title
end
end
SPECIAL KNOWLEDGE
WHAT’S WRONG WITH OO-CODE?
• WTF is “class”
SPECIAL KNOWLEDGE
WHAT’S WRONG WITH OO-CODE?
• WTF is “class”
• WTF are .new and initialize
SPECIAL KNOWLEDGE
WHAT’S WRONG WITH OO-CODE?
• WTF is “class”
• WTF are .new and initialize
• API of class
SPECIAL KNOWLEDGE
WHAT’S WRONG WITH OO-CODE?
• WTF is “class”
• WTF are .new and initialize
• API of class
• WTF are @-variables
SPECIAL KNOWLEDGE
WHAT’S WRONG WITH OO-CODE?
• WTF is “class”
• WTF are .new and initialize
• API of class
• WTF are @-variables
• difference between class and instance
SPECIAL KNOWLEDGE
WHAT’S WRONG WITH OO-CODE?
• WTF is “class”
• WTF are .new and initialize
• API of class
• WTF are @-variables
• difference between class and instance
• WTF is “attr_reader”
NO HIDDEN MAGIC
FUNCTIONAL PROGRAMMING CODE
• how to define function
NO HIDDEN MAGIC
FUNCTIONAL PROGRAMMING CODE
• how to define function
• how to call function
TO DON’T SHOOT YOUR LEG
SAFETY RULES
• do not modify, create new
TO DON’T SHOOT YOUR LEG
SAFETY RULES
• do not modify, create new
• BUY MORE RAM
TO DON’T SHOOT YOUR LEG
SAFETY RULES
• do not modify, create new
• BUY MORE RAM
• functions should not depend on environment
TO DON’T SHOOT YOUR LEG
SAFETY RULES
• do not modify, create new
• BUY MORE RAM
• functions should not depend on environment
• BUY EVEN MORE RAM
TO DON’T SHOOT YOUR LEG
SAFETY RULES
• do not modify, create new
• BUY MORE RAM
• functions should not depend on environment
• BUY EVEN MORE RAM
• avoid returns
TO DON’T SHOOT YOUR LEG
SAFETY RULES
• do not modify, create new
• BUY MORE RAM
• functions should not depend on environment
• BUY EVEN MORE RAM
• avoid returns
• use lambdas
TO DON’T SHOOT YOUR LEG
SAFETY RULES
• do not modify, create new
• BUY MORE RAM
• functions should not depend on environment
• BUY EVEN MORE RAM
• avoid returns
• use lambdas
• DO NOT FORGET TO ORDER RAM RIGHT NOW
SIDE TO SIDE RULES COMPARISON
FUNCTIONAL VS OBJECT-ORIENTED
• how to perform tasks and
how to track changes

• state changes are important
• order of execution is
important
• flow controlled by loops,
conditionals, function calls
• instances of structures and
classes
• focus on what information is
needed and what
transformations required
• state changes are non-existent
• order of execution is low-
important
• flow controlled by function
calls including recursion
• functions are first class
objects, data collections
— Greenspun’s tenth rule of programming
ANY SUFFICIENTLY COMPLICATED C OR
FORTRAN PROGRAM CONTAINS AN AD-HOC,
INFORMALLY-SPECIFIED, BUG-RIDDEN, SLOW
IMPLEMENTATION OF HALF OF COMMON LISP.
”
“
PART THREE
I AM DEVELOPER, I DON’T WANT
TO LEARN, I WANT PATTERN
MATCHING AND IMMUTABILITY
STILL EVOLVING!
FUNCTIONAL-RUBY GEM
• created by Jerry D’Antonio
STILL EVOLVING!
FUNCTIONAL-RUBY GEM
• created by Jerry D’Antonio
• inspired by Erlang, Clojure, Haskell and Functional Java
STILL EVOLVING!
FUNCTIONAL-RUBY GEM
• created by Jerry D’Antonio
• inspired by Erlang, Clojure, Haskell and Functional Java
• has records, unions and tuples
STILL EVOLVING!
FUNCTIONAL-RUBY GEM
• created by Jerry D’Antonio
• inspired by Erlang, Clojure, Haskell and Functional Java
• has records, unions and tuples
• has protocols
STILL EVOLVING!
FUNCTIONAL-RUBY GEM
• created by Jerry D’Antonio
• inspired by Erlang, Clojure, Haskell and Functional Java
• has records, unions and tuples
• has protocols
• has Erlang-style pattern matching
STILL EVOLVING!
FUNCTIONAL-RUBY GEM
• created by Jerry D’Antonio
• inspired by Erlang, Clojure, Haskell and Functional Java
• has records, unions and tuples
• has protocols
• has Erlang-style pattern matching
• has function memoization
STILL EVOLVING!
FUNCTIONAL-RUBY GEM
• created by Jerry D’Antonio
• inspired by Erlang, Clojure, Haskell and Functional Java
• has records, unions and tuples
• has protocols
• has Erlang-style pattern matching
• has function memoization
• supports MRI, JRuby and Rubinius
FUNCTIONAL-RUBY GEM
SHORT OVERVIEW
PATTERN MATCHING AND TYPE CHECKING
FUNCTIONAL-RUBY GEM
class Yoga
include Functional::PatternMatching
include Functional::TypeCheck
defn(:where_is_sun) do
puts "o"
end
defn(:where_is_sun, 14) do
puts "88!"
end
defn(:where_is_sun, _) do |name|
puts "o, #{name}!"
end
defn(:where_is_sun, _) do |name|
puts "Are you in wrong district, #{name.rude_name}?"
end.when { |name| Type?(name, Moskal) }
defn(:where_is_sun, _, _) do |name, surname|
"o, #{name} #{surname}!"
end
end
MEMOIZATION
FUNCTIONAL-RUBY GEM
class Factors
include Functional::Memo
def self.sum_of(number)
of(number).reduce(:+)
end
def self.of(number)
(1..number).select {|i| factor?(number, i)}
end
def self.factor?(number, potential)
number % potential == 0
end
memoize(:sum_of)
memoize(:of)
end
RECORDS
FUNCTIONAL-RUBY GEM
Name = Functional::Record.new(:first, :middle, :last, :suffix) do
mandatory :first, :last
default :first, 'J.'
default :last, 'Doe'
end
QUESTION
Q&A
THANK YOU

More Related Content

What's hot

TDC2016SP - Otimização Prematura: a Raíz de Todo o Mal
TDC2016SP - Otimização Prematura: a Raíz de Todo o MalTDC2016SP - Otimização Prematura: a Raíz de Todo o Mal
TDC2016SP - Otimização Prematura: a Raíz de Todo o Maltdc-globalcode
 
Refactoring RIA Unleashed 2011
Refactoring RIA Unleashed 2011Refactoring RIA Unleashed 2011
Refactoring RIA Unleashed 2011Jesse Warden
 
Social dev camp_2011
Social dev camp_2011Social dev camp_2011
Social dev camp_2011Craig Ulliott
 
Project Tools in Web Development
Project Tools in Web DevelopmentProject Tools in Web Development
Project Tools in Web Developmentkmloomis
 
Lessons from Branch's launch
Lessons from Branch's launchLessons from Branch's launch
Lessons from Branch's launchaflock
 
LeanStartup:Research is cheaper than development
LeanStartup:Research is cheaper than developmentLeanStartup:Research is cheaper than development
LeanStartup:Research is cheaper than developmentJohn McCaffrey
 
AWS Users Meetup April 2015
AWS Users Meetup April 2015AWS Users Meetup April 2015
AWS Users Meetup April 2015Jervin Real
 
Conexão Kinghost - Otimização Prematura
Conexão Kinghost - Otimização PrematuraConexão Kinghost - Otimização Prematura
Conexão Kinghost - Otimização PrematuraFabio Akita
 
Scala for android
Scala for androidScala for android
Scala for androidTack Mobile
 
Premature optimisation: The Root of All Evil
Premature optimisation: The Root of All EvilPremature optimisation: The Root of All Evil
Premature optimisation: The Root of All EvilFabio Akita
 
PRDC-ror-trilogy-part1
PRDC-ror-trilogy-part1PRDC-ror-trilogy-part1
PRDC-ror-trilogy-part1Amir Barylko
 
Better Framework Better Life
Better Framework Better LifeBetter Framework Better Life
Better Framework Better Lifejeffz
 
The Open Commerce Conference - Premature Optimisation: The Root of All Evil
The Open Commerce Conference - Premature Optimisation: The Root of All EvilThe Open Commerce Conference - Premature Optimisation: The Root of All Evil
The Open Commerce Conference - Premature Optimisation: The Root of All EvilFabio Akita
 
Effectively Using UI Automation
Effectively Using UI AutomationEffectively Using UI Automation
Effectively Using UI AutomationAlexander Repty
 
Developing Complex WordPress Sites without Fear of Failure (with MVC)
Developing Complex WordPress Sites without Fear of Failure (with MVC)Developing Complex WordPress Sites without Fear of Failure (with MVC)
Developing Complex WordPress Sites without Fear of Failure (with MVC)Mike Schinkel
 
Sensus Uses Liferay to Strengthen Their Global Web Presence
Sensus Uses Liferay to Strengthen Their Global Web PresenceSensus Uses Liferay to Strengthen Their Global Web Presence
Sensus Uses Liferay to Strengthen Their Global Web Presencerivetlogic
 
Devops kc meetup_5_20_2013
Devops kc meetup_5_20_2013Devops kc meetup_5_20_2013
Devops kc meetup_5_20_2013Aaron Blythe
 

What's hot (18)

TDC2016SP - Otimização Prematura: a Raíz de Todo o Mal
TDC2016SP - Otimização Prematura: a Raíz de Todo o MalTDC2016SP - Otimização Prematura: a Raíz de Todo o Mal
TDC2016SP - Otimização Prematura: a Raíz de Todo o Mal
 
Refactoring RIA Unleashed 2011
Refactoring RIA Unleashed 2011Refactoring RIA Unleashed 2011
Refactoring RIA Unleashed 2011
 
Social dev camp_2011
Social dev camp_2011Social dev camp_2011
Social dev camp_2011
 
Project Tools in Web Development
Project Tools in Web DevelopmentProject Tools in Web Development
Project Tools in Web Development
 
Lessons from Branch's launch
Lessons from Branch's launchLessons from Branch's launch
Lessons from Branch's launch
 
LeanStartup:Research is cheaper than development
LeanStartup:Research is cheaper than developmentLeanStartup:Research is cheaper than development
LeanStartup:Research is cheaper than development
 
OOP in JS
OOP in JSOOP in JS
OOP in JS
 
AWS Users Meetup April 2015
AWS Users Meetup April 2015AWS Users Meetup April 2015
AWS Users Meetup April 2015
 
Conexão Kinghost - Otimização Prematura
Conexão Kinghost - Otimização PrematuraConexão Kinghost - Otimização Prematura
Conexão Kinghost - Otimização Prematura
 
Scala for android
Scala for androidScala for android
Scala for android
 
Premature optimisation: The Root of All Evil
Premature optimisation: The Root of All EvilPremature optimisation: The Root of All Evil
Premature optimisation: The Root of All Evil
 
PRDC-ror-trilogy-part1
PRDC-ror-trilogy-part1PRDC-ror-trilogy-part1
PRDC-ror-trilogy-part1
 
Better Framework Better Life
Better Framework Better LifeBetter Framework Better Life
Better Framework Better Life
 
The Open Commerce Conference - Premature Optimisation: The Root of All Evil
The Open Commerce Conference - Premature Optimisation: The Root of All EvilThe Open Commerce Conference - Premature Optimisation: The Root of All Evil
The Open Commerce Conference - Premature Optimisation: The Root of All Evil
 
Effectively Using UI Automation
Effectively Using UI AutomationEffectively Using UI Automation
Effectively Using UI Automation
 
Developing Complex WordPress Sites without Fear of Failure (with MVC)
Developing Complex WordPress Sites without Fear of Failure (with MVC)Developing Complex WordPress Sites without Fear of Failure (with MVC)
Developing Complex WordPress Sites without Fear of Failure (with MVC)
 
Sensus Uses Liferay to Strengthen Their Global Web Presence
Sensus Uses Liferay to Strengthen Their Global Web PresenceSensus Uses Liferay to Strengthen Their Global Web Presence
Sensus Uses Liferay to Strengthen Their Global Web Presence
 
Devops kc meetup_5_20_2013
Devops kc meetup_5_20_2013Devops kc meetup_5_20_2013
Devops kc meetup_5_20_2013
 

Viewers also liked

Design Pattern From Java To Ruby
Design Pattern From Java To RubyDesign Pattern From Java To Ruby
Design Pattern From Java To Rubyyelogic
 
デザインパターン(初歩的な7パターン)
デザインパターン(初歩的な7パターン)デザインパターン(初歩的な7パターン)
デザインパターン(初歩的な7パターン)和明 斎藤
 
エクストリームエンジニア1
エクストリームエンジニア1エクストリームエンジニア1
エクストリームエンジニア1T-arts
 
Metaprogramming With Ruby
Metaprogramming With RubyMetaprogramming With Ruby
Metaprogramming With RubyFarooq Ali
 
The way to the timeless way of programming
The way to the timeless way of programmingThe way to the timeless way of programming
The way to the timeless way of programmingShintaro Kakutani
 
Strategy パターンと開放/閉鎖原則に見るデザインパターンの有用性
Strategy パターンと開放/閉鎖原則に見るデザインパターンの有用性Strategy パターンと開放/閉鎖原則に見るデザインパターンの有用性
Strategy パターンと開放/閉鎖原則に見るデザインパターンの有用性tomo_masakura
 

Viewers also liked (9)

Design Pattern From Java To Ruby
Design Pattern From Java To RubyDesign Pattern From Java To Ruby
Design Pattern From Java To Ruby
 
デザインパターン(初歩的な7パターン)
デザインパターン(初歩的な7パターン)デザインパターン(初歩的な7パターン)
デザインパターン(初歩的な7パターン)
 
エクストリームエンジニア1
エクストリームエンジニア1エクストリームエンジニア1
エクストリームエンジニア1
 
Basic Rails Training
Basic Rails TrainingBasic Rails Training
Basic Rails Training
 
Firefox-Addons
Firefox-AddonsFirefox-Addons
Firefox-Addons
 
Metaprogramming With Ruby
Metaprogramming With RubyMetaprogramming With Ruby
Metaprogramming With Ruby
 
The way to the timeless way of programming
The way to the timeless way of programmingThe way to the timeless way of programming
The way to the timeless way of programming
 
Design Patterns in Ruby
Design Patterns in RubyDesign Patterns in Ruby
Design Patterns in Ruby
 
Strategy パターンと開放/閉鎖原則に見るデザインパターンの有用性
Strategy パターンと開放/閉鎖原則に見るデザインパターンの有用性Strategy パターンと開放/閉鎖原則に見るデザインパターンの有用性
Strategy パターンと開放/閉鎖原則に見るデザインパターンの有用性
 

Similar to Functional Ruby

Adopting Elixir in a 10 year old codebase
Adopting Elixir in a 10 year old codebaseAdopting Elixir in a 10 year old codebase
Adopting Elixir in a 10 year old codebaseMichael Klishin
 
Meta Programming in Ruby - Code Camp 2010
Meta Programming in Ruby - Code Camp 2010Meta Programming in Ruby - Code Camp 2010
Meta Programming in Ruby - Code Camp 2010ssoroka
 
Software Engineering Thailand: Programming with Scala
Software Engineering Thailand: Programming with ScalaSoftware Engineering Thailand: Programming with Scala
Software Engineering Thailand: Programming with ScalaBrian Topping
 
Functional programming techniques in regular JavaScript
Functional programming techniques in regular JavaScriptFunctional programming techniques in regular JavaScript
Functional programming techniques in regular JavaScriptPavel Klimiankou
 
Becoming a more Productive Rails Developer
Becoming a more Productive Rails DeveloperBecoming a more Productive Rails Developer
Becoming a more Productive Rails DeveloperJohn McCaffrey
 
Tackling Testing Telephony
Tackling Testing Telephony Tackling Testing Telephony
Tackling Testing Telephony Mojo Lingo
 
Different Ways of Integrating React into Rails - Pros and Cons
Different Ways of Integrating React into Rails - Pros and ConsDifferent Ways of Integrating React into Rails - Pros and Cons
Different Ways of Integrating React into Rails - Pros and ConsAmoniac OÜ
 
Different ways of integrating React into Rails - Mikhail Bortnyk
Different ways of integrating React into Rails - Mikhail BortnykDifferent ways of integrating React into Rails - Mikhail Bortnyk
Different ways of integrating React into Rails - Mikhail BortnykRuby Meditation
 
Scaling with swagger
Scaling with swaggerScaling with swagger
Scaling with swaggerTony Tam
 
Learn Ruby 2011 - Session 1
Learn Ruby 2011 - Session 1Learn Ruby 2011 - Session 1
Learn Ruby 2011 - Session 1James Thompson
 
Inside Wordnik's Architecture
Inside Wordnik's ArchitectureInside Wordnik's Architecture
Inside Wordnik's ArchitectureTony Tam
 
AJAX & jQuery - City University WAD Module
AJAX & jQuery - City University WAD ModuleAJAX & jQuery - City University WAD Module
AJAX & jQuery - City University WAD ModuleCharlie Perrins
 
Apache Solr - search for everyone!
Apache Solr - search for everyone!Apache Solr - search for everyone!
Apache Solr - search for everyone!Jaran Flaath
 
Erlang - Dive Right In
Erlang - Dive Right InErlang - Dive Right In
Erlang - Dive Right Invorn
 
Scala in the Wild
Scala in the WildScala in the Wild
Scala in the WildTomer Gabel
 

Similar to Functional Ruby (20)

Adopting Elixir in a 10 year old codebase
Adopting Elixir in a 10 year old codebaseAdopting Elixir in a 10 year old codebase
Adopting Elixir in a 10 year old codebase
 
Meta Programming in Ruby - Code Camp 2010
Meta Programming in Ruby - Code Camp 2010Meta Programming in Ruby - Code Camp 2010
Meta Programming in Ruby - Code Camp 2010
 
Software Engineering Thailand: Programming with Scala
Software Engineering Thailand: Programming with ScalaSoftware Engineering Thailand: Programming with Scala
Software Engineering Thailand: Programming with Scala
 
Functional programming techniques in regular JavaScript
Functional programming techniques in regular JavaScriptFunctional programming techniques in regular JavaScript
Functional programming techniques in regular JavaScript
 
Becoming a more Productive Rails Developer
Becoming a more Productive Rails DeveloperBecoming a more Productive Rails Developer
Becoming a more Productive Rails Developer
 
Polyglot Grails
Polyglot GrailsPolyglot Grails
Polyglot Grails
 
Lexing and parsing
Lexing and parsingLexing and parsing
Lexing and parsing
 
Tackling Testing Telephony
Tackling Testing Telephony Tackling Testing Telephony
Tackling Testing Telephony
 
Different Ways of Integrating React into Rails - Pros and Cons
Different Ways of Integrating React into Rails - Pros and ConsDifferent Ways of Integrating React into Rails - Pros and Cons
Different Ways of Integrating React into Rails - Pros and Cons
 
Different ways of integrating React into Rails - Mikhail Bortnyk
Different ways of integrating React into Rails - Mikhail BortnykDifferent ways of integrating React into Rails - Mikhail Bortnyk
Different ways of integrating React into Rails - Mikhail Bortnyk
 
Jquery2012 defs
Jquery2012 defsJquery2012 defs
Jquery2012 defs
 
Scaling with swagger
Scaling with swaggerScaling with swagger
Scaling with swagger
 
Learn Ruby 2011 - Session 1
Learn Ruby 2011 - Session 1Learn Ruby 2011 - Session 1
Learn Ruby 2011 - Session 1
 
Testing gone-right
Testing gone-rightTesting gone-right
Testing gone-right
 
3 years with Clojure
3 years with Clojure3 years with Clojure
3 years with Clojure
 
Inside Wordnik's Architecture
Inside Wordnik's ArchitectureInside Wordnik's Architecture
Inside Wordnik's Architecture
 
AJAX & jQuery - City University WAD Module
AJAX & jQuery - City University WAD ModuleAJAX & jQuery - City University WAD Module
AJAX & jQuery - City University WAD Module
 
Apache Solr - search for everyone!
Apache Solr - search for everyone!Apache Solr - search for everyone!
Apache Solr - search for everyone!
 
Erlang - Dive Right In
Erlang - Dive Right InErlang - Dive Right In
Erlang - Dive Right In
 
Scala in the Wild
Scala in the WildScala in the Wild
Scala in the Wild
 

More from Amoniac OÜ

Dokku your own heroku 21
Dokku   your own heroku 21Dokku   your own heroku 21
Dokku your own heroku 21Amoniac OÜ
 
GO in Heterogeneous Language Environments
GO in Heterogeneous Language EnvironmentsGO in Heterogeneous Language Environments
GO in Heterogeneous Language EnvironmentsAmoniac OÜ
 
Cleaners of Caribbean
Cleaners of CaribbeanCleaners of Caribbean
Cleaners of CaribbeanAmoniac OÜ
 
Ruby JIT Compilation
Ruby JIT CompilationRuby JIT Compilation
Ruby JIT CompilationAmoniac OÜ
 
Ambiguous Sinatra
Ambiguous SinatraAmbiguous Sinatra
Ambiguous SinatraAmoniac OÜ
 
Capistrano and SystemD
Capistrano and SystemDCapistrano and SystemD
Capistrano and SystemDAmoniac OÜ
 
Distributed Cluster in Ruby
Distributed Cluster in RubyDistributed Cluster in Ruby
Distributed Cluster in RubyAmoniac OÜ
 
Roda: Putting the Fun Back into Ruby Web Development
Roda: Putting the Fun Back into Ruby Web DevelopmentRoda: Putting the Fun Back into Ruby Web Development
Roda: Putting the Fun Back into Ruby Web DevelopmentAmoniac OÜ
 
Rubymotion: Overview and Ecosystem
Rubymotion: Overview and EcosystemRubymotion: Overview and Ecosystem
Rubymotion: Overview and EcosystemAmoniac OÜ
 
Functional Web Apps with WebMachine Framework
Functional Web Apps with WebMachine FrameworkFunctional Web Apps with WebMachine Framework
Functional Web Apps with WebMachine FrameworkAmoniac OÜ
 
How to Become a Сhef
How to Become a СhefHow to Become a Сhef
How to Become a СhefAmoniac OÜ
 
Let's Count Bytes! Launching Ruby in 32K of RAM
Let's Count Bytes! Launching Ruby in 32K of RAMLet's Count Bytes! Launching Ruby in 32K of RAM
Let's Count Bytes! Launching Ruby in 32K of RAMAmoniac OÜ
 
Deployment tales
Deployment talesDeployment tales
Deployment talesAmoniac OÜ
 

More from Amoniac OÜ (14)

Dokku your own heroku 21
Dokku   your own heroku 21Dokku   your own heroku 21
Dokku your own heroku 21
 
GO in Heterogeneous Language Environments
GO in Heterogeneous Language EnvironmentsGO in Heterogeneous Language Environments
GO in Heterogeneous Language Environments
 
Cleaners of Caribbean
Cleaners of CaribbeanCleaners of Caribbean
Cleaners of Caribbean
 
Ruby JIT Compilation
Ruby JIT CompilationRuby JIT Compilation
Ruby JIT Compilation
 
Ambiguous Sinatra
Ambiguous SinatraAmbiguous Sinatra
Ambiguous Sinatra
 
Capistrano and SystemD
Capistrano and SystemDCapistrano and SystemD
Capistrano and SystemD
 
Distributed Cluster in Ruby
Distributed Cluster in RubyDistributed Cluster in Ruby
Distributed Cluster in Ruby
 
Roda: Putting the Fun Back into Ruby Web Development
Roda: Putting the Fun Back into Ruby Web DevelopmentRoda: Putting the Fun Back into Ruby Web Development
Roda: Putting the Fun Back into Ruby Web Development
 
Rubymotion: Overview and Ecosystem
Rubymotion: Overview and EcosystemRubymotion: Overview and Ecosystem
Rubymotion: Overview and Ecosystem
 
Rupher
RupherRupher
Rupher
 
Functional Web Apps with WebMachine Framework
Functional Web Apps with WebMachine FrameworkFunctional Web Apps with WebMachine Framework
Functional Web Apps with WebMachine Framework
 
How to Become a Сhef
How to Become a СhefHow to Become a Сhef
How to Become a Сhef
 
Let's Count Bytes! Launching Ruby in 32K of RAM
Let's Count Bytes! Launching Ruby in 32K of RAMLet's Count Bytes! Launching Ruby in 32K of RAM
Let's Count Bytes! Launching Ruby in 32K of RAM
 
Deployment tales
Deployment talesDeployment tales
Deployment tales
 

Recently uploaded

Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringHironori Washizaki
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxAndreas Kunz
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Rob Geurden
 
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxThe Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxRTS corp
 
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...OnePlan Solutions
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingOpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingShane Coughlan
 
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...OnePlan Solutions
 
2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shardsChristopher Curtin
 
Effectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorEffectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorTier1 app
 
Patterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencePatterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencessuser9e7c64
 
What’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesWhat’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesVictoriaMetrics
 
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...Bert Jan Schrijver
 
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesAmazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesKrzysztofKkol1
 
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecturerahul_net
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZABSYZ Inc
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identityteam-WIBU
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLionel Briand
 
Ronisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited CatalogueRonisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited Catalogueitservices996
 

Recently uploaded (20)

Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their Engineering
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...
 
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxThe Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
 
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingOpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
 
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
 
2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards
 
Effectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorEffectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryError
 
Patterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencePatterns for automating API delivery. API conference
Patterns for automating API delivery. API conference
 
What’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesWhat’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 Updates
 
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
 
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesAmazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
 
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecture
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZ
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identity
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and Repair
 
Ronisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited CatalogueRonisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited Catalogue
 

Functional Ruby

  • 2.
  • 4. ABOUT ME • Mikhail Bortnyk • Too old for this shit
  • 5. ABOUT ME • Mikhail Bortnyk • Too old for this shit • Work for Amoniac OÜ
  • 6. ABOUT ME • Mikhail Bortnyk • Too old for this shit • Work for Amoniac OÜ • Ruby developer
  • 7. ABOUT ME • Mikhail Bortnyk • Too old for this shit • Work for Amoniac OÜ • Ruby developer • Language researcher
  • 8. ABOUT ME • Mikhail Bortnyk • Too old for this shit • Work for Amoniac OÜ • Ruby developer • Language researcher • kottans.org co-founder
  • 9. ABOUT ME • Mikhail Bortnyk • Too old for this shit • Work for Amoniac OÜ • Ruby developer • Language researcher • kottans.org co-founder • twitter @mikhailbortnyk
  • 12. SIDE EFFECTS PROBLEM 1.1 • your objects store state
  • 13. SIDE EFFECTS PROBLEM 1.1 • your objects store state • your code modifies state
  • 14. SIDE EFFECTS PROBLEM 1.1 • your objects store state • your code modifies state • your other code modifies state too
  • 15. SIDE EFFECTS PROBLEM 1.1 • your objects store state • your code modifies state • your other code modifies state too • summary: mess
  • 16. SIDE EFFECTS PROBLEM 1.1 • your objects store state • your code modifies state • your other code modifies state too • summary: mess
  • 17. DATA/CODE ENTITY SHARING PROBLEM 1.2 • your model stores both your logic and data
  • 18. DATA/CODE ENTITY SHARING PROBLEM 1.2 • your model stores both your logic and data • nuff said
  • 19. DATA/CODE ENTITY SHARING PROBLEM 1.2 • your model stores both your logic and data • nuff said
  • 22. HYPE PROBLEM 1.3 • Erlang • Haskell • Scala
  • 23. HYPE PROBLEM 1.3 • Erlang • Haskell • Scala • OCaml
  • 24. HYPE PROBLEM 1.3 • Erlang • Haskell • Scala • OCaml • Lisp
  • 25. HYPE PROBLEM 1.3 • Erlang • Haskell • Scala • OCaml • Lisp • Javascript (sic!)
  • 26. HYPE PROBLEM 1.3 • Erlang • Haskell • Scala • OCaml • Lisp • Javascript (sic!) • Ruby (sic!)
  • 27. PART TWO EASY (NOT REALLY) LEVEL
  • 28. LIMITS ARE FREEING CLEAN YOUR RUBY • David Copeland article “Adventures in functional programming with Ruby”
  • 29. LIMITS ARE FREEING CLEAN YOUR RUBY • David Copeland article “Adventures in functional programming with Ruby” • Loops are just functions
  • 30. LIMITS ARE FREEING CLEAN YOUR RUBY • David Copeland article “Adventures in functional programming with Ruby” • Loops are just functions • Data structures are just functions
  • 31. LIMITS ARE FREEING CLEAN YOUR RUBY • David Copeland article “Adventures in functional programming with Ruby” • Loops are just functions • Data structures are just functions • Objects are just functions
  • 32. LIMITS ARE FREEING CLEAN YOUR RUBY • David Copeland article “Adventures in functional programming with Ruby” • Loops are just functions • Data structures are just functions • Objects are just functions • Namespaces are just functions
  • 33. LIMITS ARE FREEING CLEAN YOUR RUBY • David Copeland article “Adventures in functional programming with Ruby” • Loops are just functions • Data structures are just functions • Objects are just functions • Namespaces are just functions • P.S. Ruby HAS Tail Call Optimization
  • 34. ROUGH HACK TAIL-CALL OPTIMIZATION def fact(n, acc=1) return acc if n <= 1 fact(n-1, n*acc) end RubyVM::InstructionSequence.compile_option = { tailcall_optimization: true, trace_instruction: false } fact(1000)
  • 35. FUNCTIONAL VS OBJECT-ORIENTED SIDE TO SIDE COMPARISON new_person = ->(name, birthdate, gender, title, id=nil) { return ->(attribute) { return id if attribute == :id return name if attribute == :name return birthdate if attribute == :birthdate return gender if attribute == :gender return title if attribute == :title nil } } class Person attr_reader :id, :name, :birthdate, :gender, :title def initialize(name, birthdate, gender, title, id=nil) @id = id @name = name @birthdate = birthdate @gender = gender @title = title end end
  • 36. SPECIAL KNOWLEDGE WHAT’S WRONG WITH OO-CODE? • WTF is “class”
  • 37. SPECIAL KNOWLEDGE WHAT’S WRONG WITH OO-CODE? • WTF is “class” • WTF are .new and initialize
  • 38. SPECIAL KNOWLEDGE WHAT’S WRONG WITH OO-CODE? • WTF is “class” • WTF are .new and initialize • API of class
  • 39. SPECIAL KNOWLEDGE WHAT’S WRONG WITH OO-CODE? • WTF is “class” • WTF are .new and initialize • API of class • WTF are @-variables
  • 40. SPECIAL KNOWLEDGE WHAT’S WRONG WITH OO-CODE? • WTF is “class” • WTF are .new and initialize • API of class • WTF are @-variables • difference between class and instance
  • 41. SPECIAL KNOWLEDGE WHAT’S WRONG WITH OO-CODE? • WTF is “class” • WTF are .new and initialize • API of class • WTF are @-variables • difference between class and instance • WTF is “attr_reader”
  • 42. NO HIDDEN MAGIC FUNCTIONAL PROGRAMMING CODE • how to define function
  • 43. NO HIDDEN MAGIC FUNCTIONAL PROGRAMMING CODE • how to define function • how to call function
  • 44. TO DON’T SHOOT YOUR LEG SAFETY RULES • do not modify, create new
  • 45. TO DON’T SHOOT YOUR LEG SAFETY RULES • do not modify, create new • BUY MORE RAM
  • 46. TO DON’T SHOOT YOUR LEG SAFETY RULES • do not modify, create new • BUY MORE RAM • functions should not depend on environment
  • 47. TO DON’T SHOOT YOUR LEG SAFETY RULES • do not modify, create new • BUY MORE RAM • functions should not depend on environment • BUY EVEN MORE RAM
  • 48. TO DON’T SHOOT YOUR LEG SAFETY RULES • do not modify, create new • BUY MORE RAM • functions should not depend on environment • BUY EVEN MORE RAM • avoid returns
  • 49. TO DON’T SHOOT YOUR LEG SAFETY RULES • do not modify, create new • BUY MORE RAM • functions should not depend on environment • BUY EVEN MORE RAM • avoid returns • use lambdas
  • 50. TO DON’T SHOOT YOUR LEG SAFETY RULES • do not modify, create new • BUY MORE RAM • functions should not depend on environment • BUY EVEN MORE RAM • avoid returns • use lambdas • DO NOT FORGET TO ORDER RAM RIGHT NOW
  • 51. SIDE TO SIDE RULES COMPARISON FUNCTIONAL VS OBJECT-ORIENTED • how to perform tasks and how to track changes
 • state changes are important • order of execution is important • flow controlled by loops, conditionals, function calls • instances of structures and classes • focus on what information is needed and what transformations required • state changes are non-existent • order of execution is low- important • flow controlled by function calls including recursion • functions are first class objects, data collections
  • 52. — Greenspun’s tenth rule of programming ANY SUFFICIENTLY COMPLICATED C OR FORTRAN PROGRAM CONTAINS AN AD-HOC, INFORMALLY-SPECIFIED, BUG-RIDDEN, SLOW IMPLEMENTATION OF HALF OF COMMON LISP. ” “
  • 53. PART THREE I AM DEVELOPER, I DON’T WANT TO LEARN, I WANT PATTERN MATCHING AND IMMUTABILITY
  • 54. STILL EVOLVING! FUNCTIONAL-RUBY GEM • created by Jerry D’Antonio
  • 55. STILL EVOLVING! FUNCTIONAL-RUBY GEM • created by Jerry D’Antonio • inspired by Erlang, Clojure, Haskell and Functional Java
  • 56. STILL EVOLVING! FUNCTIONAL-RUBY GEM • created by Jerry D’Antonio • inspired by Erlang, Clojure, Haskell and Functional Java • has records, unions and tuples
  • 57. STILL EVOLVING! FUNCTIONAL-RUBY GEM • created by Jerry D’Antonio • inspired by Erlang, Clojure, Haskell and Functional Java • has records, unions and tuples • has protocols
  • 58. STILL EVOLVING! FUNCTIONAL-RUBY GEM • created by Jerry D’Antonio • inspired by Erlang, Clojure, Haskell and Functional Java • has records, unions and tuples • has protocols • has Erlang-style pattern matching
  • 59. STILL EVOLVING! FUNCTIONAL-RUBY GEM • created by Jerry D’Antonio • inspired by Erlang, Clojure, Haskell and Functional Java • has records, unions and tuples • has protocols • has Erlang-style pattern matching • has function memoization
  • 60. STILL EVOLVING! FUNCTIONAL-RUBY GEM • created by Jerry D’Antonio • inspired by Erlang, Clojure, Haskell and Functional Java • has records, unions and tuples • has protocols • has Erlang-style pattern matching • has function memoization • supports MRI, JRuby and Rubinius
  • 62. PATTERN MATCHING AND TYPE CHECKING FUNCTIONAL-RUBY GEM class Yoga include Functional::PatternMatching include Functional::TypeCheck defn(:where_is_sun) do puts "o" end defn(:where_is_sun, 14) do puts "88!" end defn(:where_is_sun, _) do |name| puts "o, #{name}!" end defn(:where_is_sun, _) do |name| puts "Are you in wrong district, #{name.rude_name}?" end.when { |name| Type?(name, Moskal) } defn(:where_is_sun, _, _) do |name, surname| "o, #{name} #{surname}!" end end
  • 63. MEMOIZATION FUNCTIONAL-RUBY GEM class Factors include Functional::Memo def self.sum_of(number) of(number).reduce(:+) end def self.of(number) (1..number).select {|i| factor?(number, i)} end def self.factor?(number, potential) number % potential == 0 end memoize(:sum_of) memoize(:of) end
  • 64. RECORDS FUNCTIONAL-RUBY GEM Name = Functional::Record.new(:first, :middle, :last, :suffix) do mandatory :first, :last default :first, 'J.' default :last, 'Doe' end
  • 66. Q&A