Funtional Ruby - Mikhail Bortnyk

Ruby Meditation
Ruby MeditationRuby Meditation
FUNCTIONAL
RUBY
Funtional Ruby - Mikhail Bortnyk
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
1 of 67

Recommended

Irb Tips and Tricks by
Irb Tips and TricksIrb Tips and Tricks
Irb Tips and TricksJohn McCaffrey
1.1K views9 slides
Build a Startup with Clojure(Script) by
Build a Startup with Clojure(Script)Build a Startup with Clojure(Script)
Build a Startup with Clojure(Script)Théophile Villard
644 views107 slides
Forget The ORM! by
Forget The ORM!Forget The ORM!
Forget The ORM!Randal Schwartz
3.8K views298 slides
Becoming a more productive Rails Developer by
Becoming a more productive Rails DeveloperBecoming a more productive Rails Developer
Becoming a more productive Rails DeveloperJohn McCaffrey
794 views54 slides
Freelancing and side-projects on Rails by
Freelancing and side-projects on RailsFreelancing and side-projects on Rails
Freelancing and side-projects on RailsJohn McCaffrey
1.4K views30 slides
Windycityrails page performance by
Windycityrails page performanceWindycityrails page performance
Windycityrails page performanceJohn McCaffrey
2.9K views136 slides

More Related Content

What's hot

TDC2016SP - Otimização Prematura: a Raíz de Todo o Mal by
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
390 views126 slides
Refactoring RIA Unleashed 2011 by
Refactoring RIA Unleashed 2011Refactoring RIA Unleashed 2011
Refactoring RIA Unleashed 2011Jesse Warden
767 views265 slides
Social dev camp_2011 by
Social dev camp_2011Social dev camp_2011
Social dev camp_2011Craig Ulliott
608 views83 slides
Project Tools in Web Development by
Project Tools in Web DevelopmentProject Tools in Web Development
Project Tools in Web Developmentkmloomis
471 views127 slides
Lessons from Branch's launch by
Lessons from Branch's launchLessons from Branch's launch
Lessons from Branch's launchaflock
770 views45 slides
LeanStartup:Research is cheaper than development by
LeanStartup:Research is cheaper than developmentLeanStartup:Research is cheaper than development
LeanStartup:Research is cheaper than developmentJohn McCaffrey
1K views43 slides

What's hot(18)

TDC2016SP - Otimização Prematura: a Raíz de Todo o Mal by tdc-globalcode
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
tdc-globalcode390 views
Refactoring RIA Unleashed 2011 by Jesse Warden
Refactoring RIA Unleashed 2011Refactoring RIA Unleashed 2011
Refactoring RIA Unleashed 2011
Jesse Warden767 views
Project Tools in Web Development by kmloomis
Project Tools in Web DevelopmentProject Tools in Web Development
Project Tools in Web Development
kmloomis471 views
Lessons from Branch's launch by aflock
Lessons from Branch's launchLessons from Branch's launch
Lessons from Branch's launch
aflock770 views
LeanStartup:Research is cheaper than development by John McCaffrey
LeanStartup:Research is cheaper than developmentLeanStartup:Research is cheaper than development
LeanStartup:Research is cheaper than development
John McCaffrey1K views
AWS Users Meetup April 2015 by Jervin Real
AWS Users Meetup April 2015AWS Users Meetup April 2015
AWS Users Meetup April 2015
Jervin Real669 views
Conexão Kinghost - Otimização Prematura by Fabio Akita
Conexão Kinghost - Otimização PrematuraConexão Kinghost - Otimização Prematura
Conexão Kinghost - Otimização Prematura
Fabio Akita1.7K views
Scala for android by Tack Mobile
Scala for androidScala for android
Scala for android
Tack Mobile1.3K views
Premature optimisation: The Root of All Evil by Fabio Akita
Premature optimisation: The Root of All EvilPremature optimisation: The Root of All Evil
Premature optimisation: The Root of All Evil
Fabio Akita1.2K views
PRDC-ror-trilogy-part1 by Amir Barylko
PRDC-ror-trilogy-part1PRDC-ror-trilogy-part1
PRDC-ror-trilogy-part1
Amir Barylko532 views
Better Framework Better Life by jeffz
Better Framework Better LifeBetter Framework Better Life
Better Framework Better Life
jeffz887 views
The Open Commerce Conference - Premature Optimisation: The Root of All Evil by Fabio Akita
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
Fabio Akita1.1K views
Effectively Using UI Automation by Alexander Repty
Effectively Using UI AutomationEffectively Using UI Automation
Effectively Using UI Automation
Alexander Repty4.6K views
Developing Complex WordPress Sites without Fear of Failure (with MVC) by Mike Schinkel
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 Schinkel1.8K views
Sensus Uses Liferay to Strengthen Their Global Web Presence by rivetlogic
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
rivetlogic1.4K views
Devops kc meetup_5_20_2013 by Aaron Blythe
Devops kc meetup_5_20_2013Devops kc meetup_5_20_2013
Devops kc meetup_5_20_2013
Aaron Blythe447 views

Viewers also liked

Ruby Gems and Native Extensions - Stas Volovyk by
Ruby Gems and Native Extensions - Stas VolovykRuby Gems and Native Extensions - Stas Volovyk
Ruby Gems and Native Extensions - Stas VolovykRuby Meditation
369 views37 slides
Evident Secrets of Successful Application - Max Goncharov by
Evident Secrets of Successful Application - Max GoncharovEvident Secrets of Successful Application - Max Goncharov
Evident Secrets of Successful Application - Max GoncharovRuby Meditation
301 views16 slides
Functional Web Apps with WebMachine Framework - Mikhail Bortnyk by
Functional Web Apps with WebMachine Framework - Mikhail BortnykFunctional Web Apps with WebMachine Framework - Mikhail Bortnyk
Functional Web Apps with WebMachine Framework - Mikhail BortnykRuby Meditation
262 views80 slides
Rodauth: Clean Authentication - Valentine Ostakh by
Rodauth: Clean Authentication - Valentine OstakhRodauth: Clean Authentication - Valentine Ostakh
Rodauth: Clean Authentication - Valentine OstakhRuby Meditation
1.3K views99 slides
Lets build a game (in 24 min) by Ivan Zarea by
Lets build a game (in 24 min) by Ivan ZareaLets build a game (in 24 min) by Ivan Zarea
Lets build a game (in 24 min) by Ivan ZareaPivorak MeetUp
233 views16 slides
Say Goodbye to Procedural Programming - Nick Sutterer by
Say Goodbye to Procedural Programming - Nick SuttererSay Goodbye to Procedural Programming - Nick Sutterer
Say Goodbye to Procedural Programming - Nick SuttererRuby Meditation
380 views178 slides

Viewers also liked(6)

Ruby Gems and Native Extensions - Stas Volovyk by Ruby Meditation
Ruby Gems and Native Extensions - Stas VolovykRuby Gems and Native Extensions - Stas Volovyk
Ruby Gems and Native Extensions - Stas Volovyk
Ruby Meditation369 views
Evident Secrets of Successful Application - Max Goncharov by Ruby Meditation
Evident Secrets of Successful Application - Max GoncharovEvident Secrets of Successful Application - Max Goncharov
Evident Secrets of Successful Application - Max Goncharov
Ruby Meditation301 views
Functional Web Apps with WebMachine Framework - Mikhail Bortnyk by Ruby Meditation
Functional Web Apps with WebMachine Framework - Mikhail BortnykFunctional Web Apps with WebMachine Framework - Mikhail Bortnyk
Functional Web Apps with WebMachine Framework - Mikhail Bortnyk
Ruby Meditation262 views
Rodauth: Clean Authentication - Valentine Ostakh by Ruby Meditation
Rodauth: Clean Authentication - Valentine OstakhRodauth: Clean Authentication - Valentine Ostakh
Rodauth: Clean Authentication - Valentine Ostakh
Ruby Meditation1.3K views
Lets build a game (in 24 min) by Ivan Zarea by Pivorak MeetUp
Lets build a game (in 24 min) by Ivan ZareaLets build a game (in 24 min) by Ivan Zarea
Lets build a game (in 24 min) by Ivan Zarea
Pivorak MeetUp233 views
Say Goodbye to Procedural Programming - Nick Sutterer by Ruby Meditation
Say Goodbye to Procedural Programming - Nick SuttererSay Goodbye to Procedural Programming - Nick Sutterer
Say Goodbye to Procedural Programming - Nick Sutterer
Ruby Meditation380 views

Similar to Funtional Ruby - Mikhail Bortnyk

Adopting Elixir in a 10 year old codebase by
Adopting Elixir in a 10 year old codebaseAdopting Elixir in a 10 year old codebase
Adopting Elixir in a 10 year old codebaseMichael Klishin
664 views79 slides
Meta Programming in Ruby - Code Camp 2010 by
Meta Programming in Ruby - Code Camp 2010Meta Programming in Ruby - Code Camp 2010
Meta Programming in Ruby - Code Camp 2010ssoroka
1.6K views366 slides
Software Engineering Thailand: Programming with Scala by
Software Engineering Thailand: Programming with ScalaSoftware Engineering Thailand: Programming with Scala
Software Engineering Thailand: Programming with ScalaBrian Topping
929 views132 slides
Functional programming techniques in regular JavaScript by
Functional programming techniques in regular JavaScriptFunctional programming techniques in regular JavaScript
Functional programming techniques in regular JavaScriptPavel Klimiankou
722 views101 slides
Becoming a more Productive Rails Developer by
Becoming a more Productive Rails DeveloperBecoming a more Productive Rails Developer
Becoming a more Productive Rails DeveloperJohn McCaffrey
4.6K views54 slides
Polyglot Grails by
Polyglot GrailsPolyglot Grails
Polyglot GrailsMarcin Gryszko
3.5K views71 slides

Similar to Funtional Ruby - Mikhail Bortnyk(20)

Adopting Elixir in a 10 year old codebase by Michael Klishin
Adopting Elixir in a 10 year old codebaseAdopting Elixir in a 10 year old codebase
Adopting Elixir in a 10 year old codebase
Michael Klishin664 views
Meta Programming in Ruby - Code Camp 2010 by ssoroka
Meta Programming in Ruby - Code Camp 2010Meta Programming in Ruby - Code Camp 2010
Meta Programming in Ruby - Code Camp 2010
ssoroka1.6K views
Software Engineering Thailand: Programming with Scala by Brian Topping
Software Engineering Thailand: Programming with ScalaSoftware Engineering Thailand: Programming with Scala
Software Engineering Thailand: Programming with Scala
Brian Topping929 views
Functional programming techniques in regular JavaScript by Pavel Klimiankou
Functional programming techniques in regular JavaScriptFunctional programming techniques in regular JavaScript
Functional programming techniques in regular JavaScript
Pavel Klimiankou722 views
Becoming a more Productive Rails Developer by John McCaffrey
Becoming a more Productive Rails DeveloperBecoming a more Productive Rails Developer
Becoming a more Productive Rails Developer
John McCaffrey4.6K views
Tackling Testing Telephony by Mojo Lingo
Tackling Testing Telephony Tackling Testing Telephony
Tackling Testing Telephony
Mojo Lingo296 views
Different Ways of Integrating React into Rails - Pros and Cons by Amoniac OÜ
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
Amoniac OÜ233 views
Different ways of integrating React into Rails - Mikhail Bortnyk by Ruby Meditation
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
Ruby Meditation742 views
Scaling with swagger by Tony Tam
Scaling with swaggerScaling with swagger
Scaling with swagger
Tony Tam6.2K views
Inside Wordnik's Architecture by Tony Tam
Inside Wordnik's ArchitectureInside Wordnik's Architecture
Inside Wordnik's Architecture
Tony Tam2.8K views
AJAX & jQuery - City University WAD Module by Charlie Perrins
AJAX & jQuery - City University WAD ModuleAJAX & jQuery - City University WAD Module
AJAX & jQuery - City University WAD Module
Charlie Perrins889 views
Apache Solr - search for everyone! by Jaran Flaath
Apache Solr - search for everyone!Apache Solr - search for everyone!
Apache Solr - search for everyone!
Jaran Flaath1.6K views
Erlang - Dive Right In by vorn
Erlang - Dive Right InErlang - Dive Right In
Erlang - Dive Right In
vorn411 views
Scala in the Wild by Tomer Gabel
Scala in the WildScala in the Wild
Scala in the Wild
Tomer Gabel2.8K views

More from Ruby Meditation

Is this Legacy or Revenant Code? - Sergey Sergyenko | Ruby Meditation 30 by
Is this Legacy or Revenant Code? - Sergey Sergyenko  | Ruby Meditation 30Is this Legacy or Revenant Code? - Sergey Sergyenko  | Ruby Meditation 30
Is this Legacy or Revenant Code? - Sergey Sergyenko | Ruby Meditation 30Ruby Meditation
207 views22 slides
Life with GraphQL API: good practices and unresolved issues - Roman Dubrovsky... by
Life with GraphQL API: good practices and unresolved issues - Roman Dubrovsky...Life with GraphQL API: good practices and unresolved issues - Roman Dubrovsky...
Life with GraphQL API: good practices and unresolved issues - Roman Dubrovsky...Ruby Meditation
462 views141 slides
Where is your license, dude? - Viacheslav Miroshnychenko | Ruby Meditation 29 by
Where is your license, dude? - Viacheslav Miroshnychenko | Ruby Meditation 29Where is your license, dude? - Viacheslav Miroshnychenko | Ruby Meditation 29
Where is your license, dude? - Viacheslav Miroshnychenko | Ruby Meditation 29Ruby Meditation
210 views49 slides
Dry-validation update. Dry-validation vs Dry-schema 1.0 - Aleksandra Stolyar ... by
Dry-validation update. Dry-validation vs Dry-schema 1.0 - Aleksandra Stolyar ...Dry-validation update. Dry-validation vs Dry-schema 1.0 - Aleksandra Stolyar ...
Dry-validation update. Dry-validation vs Dry-schema 1.0 - Aleksandra Stolyar ...Ruby Meditation
1.6K views59 slides
How to cook Rabbit on Production - Bohdan Parshentsev | Ruby Meditation 28 by
How to cook Rabbit on Production - Bohdan Parshentsev | Ruby Meditation 28 How to cook Rabbit on Production - Bohdan Parshentsev | Ruby Meditation 28
How to cook Rabbit on Production - Bohdan Parshentsev | Ruby Meditation 28 Ruby Meditation
366 views23 slides
How to cook Rabbit on Production - Serhiy Nazarov | Ruby Meditation 28 by
How to cook Rabbit on Production - Serhiy Nazarov | Ruby Meditation 28How to cook Rabbit on Production - Serhiy Nazarov | Ruby Meditation 28
How to cook Rabbit on Production - Serhiy Nazarov | Ruby Meditation 28Ruby Meditation
459 views20 slides

More from Ruby Meditation(20)

Is this Legacy or Revenant Code? - Sergey Sergyenko | Ruby Meditation 30 by Ruby Meditation
Is this Legacy or Revenant Code? - Sergey Sergyenko  | Ruby Meditation 30Is this Legacy or Revenant Code? - Sergey Sergyenko  | Ruby Meditation 30
Is this Legacy or Revenant Code? - Sergey Sergyenko | Ruby Meditation 30
Ruby Meditation207 views
Life with GraphQL API: good practices and unresolved issues - Roman Dubrovsky... by Ruby Meditation
Life with GraphQL API: good practices and unresolved issues - Roman Dubrovsky...Life with GraphQL API: good practices and unresolved issues - Roman Dubrovsky...
Life with GraphQL API: good practices and unresolved issues - Roman Dubrovsky...
Ruby Meditation462 views
Where is your license, dude? - Viacheslav Miroshnychenko | Ruby Meditation 29 by Ruby Meditation
Where is your license, dude? - Viacheslav Miroshnychenko | Ruby Meditation 29Where is your license, dude? - Viacheslav Miroshnychenko | Ruby Meditation 29
Where is your license, dude? - Viacheslav Miroshnychenko | Ruby Meditation 29
Ruby Meditation210 views
Dry-validation update. Dry-validation vs Dry-schema 1.0 - Aleksandra Stolyar ... by Ruby Meditation
Dry-validation update. Dry-validation vs Dry-schema 1.0 - Aleksandra Stolyar ...Dry-validation update. Dry-validation vs Dry-schema 1.0 - Aleksandra Stolyar ...
Dry-validation update. Dry-validation vs Dry-schema 1.0 - Aleksandra Stolyar ...
Ruby Meditation1.6K views
How to cook Rabbit on Production - Bohdan Parshentsev | Ruby Meditation 28 by Ruby Meditation
How to cook Rabbit on Production - Bohdan Parshentsev | Ruby Meditation 28 How to cook Rabbit on Production - Bohdan Parshentsev | Ruby Meditation 28
How to cook Rabbit on Production - Bohdan Parshentsev | Ruby Meditation 28
Ruby Meditation366 views
How to cook Rabbit on Production - Serhiy Nazarov | Ruby Meditation 28 by Ruby Meditation
How to cook Rabbit on Production - Serhiy Nazarov | Ruby Meditation 28How to cook Rabbit on Production - Serhiy Nazarov | Ruby Meditation 28
How to cook Rabbit on Production - Serhiy Nazarov | Ruby Meditation 28
Ruby Meditation459 views
Reinventing the wheel - why do it and how to feel good about it - Julik Tarkh... by Ruby Meditation
Reinventing the wheel - why do it and how to feel good about it - Julik Tarkh...Reinventing the wheel - why do it and how to feel good about it - Julik Tarkh...
Reinventing the wheel - why do it and how to feel good about it - Julik Tarkh...
Ruby Meditation462 views
Performance Optimization 101 for Ruby developers - Nihad Abbasov (ENG) | Ruby... by Ruby Meditation
Performance Optimization 101 for Ruby developers - Nihad Abbasov (ENG) | Ruby...Performance Optimization 101 for Ruby developers - Nihad Abbasov (ENG) | Ruby...
Performance Optimization 101 for Ruby developers - Nihad Abbasov (ENG) | Ruby...
Ruby Meditation475 views
Use cases for Serverless Technologies - Ruslan Tolstov (RUS) | Ruby Meditatio... by Ruby Meditation
Use cases for Serverless Technologies - Ruslan Tolstov (RUS) | Ruby Meditatio...Use cases for Serverless Technologies - Ruslan Tolstov (RUS) | Ruby Meditatio...
Use cases for Serverless Technologies - Ruslan Tolstov (RUS) | Ruby Meditatio...
Ruby Meditation320 views
The Trailblazer Ride from the If Jungle into a Civilised Railway Station - Or... by Ruby Meditation
The Trailblazer Ride from the If Jungle into a Civilised Railway Station - Or...The Trailblazer Ride from the If Jungle into a Civilised Railway Station - Or...
The Trailblazer Ride from the If Jungle into a Civilised Railway Station - Or...
Ruby Meditation285 views
What/How to do with GraphQL? - Valentyn Ostakh (ENG) | Ruby Meditation 27 by Ruby Meditation
What/How to do with GraphQL? - Valentyn Ostakh (ENG) | Ruby Meditation 27What/How to do with GraphQL? - Valentyn Ostakh (ENG) | Ruby Meditation 27
What/How to do with GraphQL? - Valentyn Ostakh (ENG) | Ruby Meditation 27
Ruby Meditation1.1K views
New features in Rails 6 - Nihad Abbasov (RUS) | Ruby Meditation 26 by Ruby Meditation
New features in Rails 6 -  Nihad Abbasov (RUS) | Ruby Meditation 26New features in Rails 6 -  Nihad Abbasov (RUS) | Ruby Meditation 26
New features in Rails 6 - Nihad Abbasov (RUS) | Ruby Meditation 26
Ruby Meditation577 views
Security Scanning Overview - Tetiana Chupryna (RUS) | Ruby Meditation 26 by Ruby Meditation
Security Scanning Overview - Tetiana Chupryna (RUS) | Ruby Meditation 26Security Scanning Overview - Tetiana Chupryna (RUS) | Ruby Meditation 26
Security Scanning Overview - Tetiana Chupryna (RUS) | Ruby Meditation 26
Ruby Meditation299 views
Teach your application eloquence. Logs, metrics, traces - Dmytro Shapovalov (... by Ruby Meditation
Teach your application eloquence. Logs, metrics, traces - Dmytro Shapovalov (...Teach your application eloquence. Logs, metrics, traces - Dmytro Shapovalov (...
Teach your application eloquence. Logs, metrics, traces - Dmytro Shapovalov (...
Ruby Meditation455 views
Best practices. Exploring - Ike Kurghinyan (RUS) | Ruby Meditation 26 by Ruby Meditation
Best practices. Exploring - Ike Kurghinyan (RUS) | Ruby Meditation 26Best practices. Exploring - Ike Kurghinyan (RUS) | Ruby Meditation 26
Best practices. Exploring - Ike Kurghinyan (RUS) | Ruby Meditation 26
Ruby Meditation204 views
Road to A/B testing - Alexey Vasiliev (ENG) | Ruby Meditation 25 by Ruby Meditation
Road to A/B testing - Alexey Vasiliev (ENG) | Ruby Meditation 25Road to A/B testing - Alexey Vasiliev (ENG) | Ruby Meditation 25
Road to A/B testing - Alexey Vasiliev (ENG) | Ruby Meditation 25
Ruby Meditation577 views
Concurrency in production. Real life example - Dmytro Herasymuk | Ruby Medita... by Ruby Meditation
Concurrency in production. Real life example - Dmytro Herasymuk | Ruby Medita...Concurrency in production. Real life example - Dmytro Herasymuk | Ruby Medita...
Concurrency in production. Real life example - Dmytro Herasymuk | Ruby Medita...
Ruby Meditation511 views
Data encryption for Ruby web applications - Dmytro Shapovalov (RUS) | Ruby Me... by Ruby Meditation
Data encryption for Ruby web applications - Dmytro Shapovalov (RUS) | Ruby Me...Data encryption for Ruby web applications - Dmytro Shapovalov (RUS) | Ruby Me...
Data encryption for Ruby web applications - Dmytro Shapovalov (RUS) | Ruby Me...
Ruby Meditation299 views
Rails App performance at the limit - Bogdan Gusiev by Ruby Meditation
Rails App performance at the limit - Bogdan GusievRails App performance at the limit - Bogdan Gusiev
Rails App performance at the limit - Bogdan Gusiev
Ruby Meditation418 views
GDPR. Next Y2K in 2018? - Anton Tkachov | Ruby Meditation #23 by Ruby Meditation
GDPR. Next Y2K in 2018? - Anton Tkachov | Ruby Meditation #23GDPR. Next Y2K in 2018? - Anton Tkachov | Ruby Meditation #23
GDPR. Next Y2K in 2018? - Anton Tkachov | Ruby Meditation #23
Ruby Meditation179 views

Recently uploaded

Optimizing Communication to Optimize Human Behavior - LCBM by
Optimizing Communication to Optimize Human Behavior - LCBMOptimizing Communication to Optimize Human Behavior - LCBM
Optimizing Communication to Optimize Human Behavior - LCBMYaman Kumar
38 views49 slides
Business Analyst Series 2023 - Week 4 Session 7 by
Business Analyst Series 2023 -  Week 4 Session 7Business Analyst Series 2023 -  Week 4 Session 7
Business Analyst Series 2023 - Week 4 Session 7DianaGray10
146 views31 slides
Don’t Make A Human Do A Robot’s Job! : 6 Reasons Why AI Will Save Us & Not De... by
Don’t Make A Human Do A Robot’s Job! : 6 Reasons Why AI Will Save Us & Not De...Don’t Make A Human Do A Robot’s Job! : 6 Reasons Why AI Will Save Us & Not De...
Don’t Make A Human Do A Robot’s Job! : 6 Reasons Why AI Will Save Us & Not De...Moses Kemibaro
35 views38 slides
Future of AR - Facebook Presentation by
Future of AR - Facebook PresentationFuture of AR - Facebook Presentation
Future of AR - Facebook PresentationRob McCarty
65 views27 slides
Generative AI: Shifting the AI Landscape by
Generative AI: Shifting the AI LandscapeGenerative AI: Shifting the AI Landscape
Generative AI: Shifting the AI LandscapeDeakin University
67 views55 slides
The Power of Heat Decarbonisation Plans in the Built Environment by
The Power of Heat Decarbonisation Plans in the Built EnvironmentThe Power of Heat Decarbonisation Plans in the Built Environment
The Power of Heat Decarbonisation Plans in the Built EnvironmentIES VE
84 views20 slides

Recently uploaded(20)

Optimizing Communication to Optimize Human Behavior - LCBM by Yaman Kumar
Optimizing Communication to Optimize Human Behavior - LCBMOptimizing Communication to Optimize Human Behavior - LCBM
Optimizing Communication to Optimize Human Behavior - LCBM
Yaman Kumar38 views
Business Analyst Series 2023 - Week 4 Session 7 by DianaGray10
Business Analyst Series 2023 -  Week 4 Session 7Business Analyst Series 2023 -  Week 4 Session 7
Business Analyst Series 2023 - Week 4 Session 7
DianaGray10146 views
Don’t Make A Human Do A Robot’s Job! : 6 Reasons Why AI Will Save Us & Not De... by Moses Kemibaro
Don’t Make A Human Do A Robot’s Job! : 6 Reasons Why AI Will Save Us & Not De...Don’t Make A Human Do A Robot’s Job! : 6 Reasons Why AI Will Save Us & Not De...
Don’t Make A Human Do A Robot’s Job! : 6 Reasons Why AI Will Save Us & Not De...
Moses Kemibaro35 views
Future of AR - Facebook Presentation by Rob McCarty
Future of AR - Facebook PresentationFuture of AR - Facebook Presentation
Future of AR - Facebook Presentation
Rob McCarty65 views
The Power of Heat Decarbonisation Plans in the Built Environment by IES VE
The Power of Heat Decarbonisation Plans in the Built EnvironmentThe Power of Heat Decarbonisation Plans in the Built Environment
The Power of Heat Decarbonisation Plans in the Built Environment
IES VE84 views
State of the Union - Rohit Yadav - Apache CloudStack by ShapeBlue
State of the Union - Rohit Yadav - Apache CloudStackState of the Union - Rohit Yadav - Apache CloudStack
State of the Union - Rohit Yadav - Apache CloudStack
ShapeBlue303 views
Enabling DPU Hardware Accelerators in XCP-ng Cloud Platform Environment - And... by ShapeBlue
Enabling DPU Hardware Accelerators in XCP-ng Cloud Platform Environment - And...Enabling DPU Hardware Accelerators in XCP-ng Cloud Platform Environment - And...
Enabling DPU Hardware Accelerators in XCP-ng Cloud Platform Environment - And...
ShapeBlue108 views
CloudStack Managed User Data and Demo - Harikrishna Patnala - ShapeBlue by ShapeBlue
CloudStack Managed User Data and Demo - Harikrishna Patnala - ShapeBlueCloudStack Managed User Data and Demo - Harikrishna Patnala - ShapeBlue
CloudStack Managed User Data and Demo - Harikrishna Patnala - ShapeBlue
ShapeBlue137 views
Live Demo Showcase: Unveiling Dell PowerFlex’s IaaS Capabilities with Apache ... by ShapeBlue
Live Demo Showcase: Unveiling Dell PowerFlex’s IaaS Capabilities with Apache ...Live Demo Showcase: Unveiling Dell PowerFlex’s IaaS Capabilities with Apache ...
Live Demo Showcase: Unveiling Dell PowerFlex’s IaaS Capabilities with Apache ...
ShapeBlue129 views
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ... by Jasper Oosterveld
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P... by ShapeBlue
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...
ShapeBlue196 views
"Running students' code in isolation. The hard way", Yurii Holiuk by Fwdays
"Running students' code in isolation. The hard way", Yurii Holiuk "Running students' code in isolation. The hard way", Yurii Holiuk
"Running students' code in isolation. The hard way", Yurii Holiuk
Fwdays36 views
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue by ShapeBlue
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlueCloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue
ShapeBlue139 views
Transcript: Redefining the book supply chain: A glimpse into the future - Tec... by BookNet Canada
Transcript: Redefining the book supply chain: A glimpse into the future - Tec...Transcript: Redefining the book supply chain: A glimpse into the future - Tec...
Transcript: Redefining the book supply chain: A glimpse into the future - Tec...
BookNet Canada41 views
What’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlue by ShapeBlue
What’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlueWhat’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlue
What’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlue
ShapeBlue265 views
Updates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBIT by ShapeBlue
Updates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBITUpdates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBIT
Updates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBIT
ShapeBlue208 views

Funtional Ruby - Mikhail Bortnyk

  • 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