SlideShare a Scribd company logo
Introduction to Functional
Programming and Clojure
@sdaas
What to Expect …
• Look at programming in a different way
– Immutable data
– A world without for-loops
• Understand basics of functional programming
– In the context of Clojure
• A POV on why to consider a functional
programming style in your current project
• And why Clojure might be a good choice
What NOT to Expect …
• NOT a deep dive into all aspects of the Clojure
programming language
• NOT about installation, debugging,
performance, etc. of Clojure
• NO bashing of Java or any other language
• NO bashing of Object-Oriented Design
Don’t forget Java yet …
• FP is a programming paradigm or style
• Some languages lend themselves better to
functional programming
– Clojure, Haskell, Erlang
• Most languages support FP to some extent
– Java 8
– JavaScript
– Python
Functional Programming Concepts
• More like Mathematical Functions
– vs. Subroutines/procedures
• Support higher order functions
• Pure functions – with no side effects
• Recursion is favored over iteration
• Lazy Evaluation
• Referential Transparency
– Once defined, a “variable” never changes value
What is Clojure ?
• Created by Rich Hickey
• Immutable and Functional Programming style
• Lisp that runs on the JVM
• Interoperates with Java
• Power of Functional Programming meets the
Richness of Java Ecosystem
Clojure Syntax
Functions
Lists
• Collection of heterogeneous values
• Operations on lists never modify the original
list. They always return a copy.
• This “immutability” of data structure is a big
deal in Functional Programing.
• Two fundamental operators – first, & rest
• Every data structure and function is built up
using these two operators
Lists
Building Blocks – first & rest
• Favoring recursion over iteration
• Do you see the bomb in the nth-element ?
Tail recursion is your friend
Map, Filter, and Reduce
Composition
• FP encourages you to compose small/simpler
function to create complex functions
What does this code do ?
Sum of square of all odd numbers ..
• How testable and maintainable is this code ?
• Modify this for odd numbers that aren’t multiples of 7 ?
• How would this work for infinitely long data ?
Functional Version …
Find the first 20 prime numbers
Laziness is good ...
• Iterate : returns lazy sequence of f(x) f(f(x)) etc ..
• take : returns a lazy sequence of first n from collection
• Map and filter can work on lazy sequences
• Check out the call to java.lang.Math.sqrt
Hash Maps
Reading a CSV File …
FROM
Smith,John,45,90210
Frank,Peter,25,90110
Bond,James,38,90110
TO
{:zip 90210, :age 45, :fname "John", :lname "Smith"}
{:zip 90110, :age 25, :fname "Peter", :lname "Frank"}
{:zip 90110, :age 38, :fname "James", :lname "Bond"}
12 lines of Clojure Code …
What the %$*&^ was that ?
In Summary …
• FP concepts can be used to create concise,
highly modular, and composable code
• Java 8 and JavaScript have good support for FP
concepts
• Clojure interoperates well with Java, and could
be a good way to experiment with FP without
abandoning the Java ecosystem
Questions ?
Please give your feedback at
http://bit.ly/introfp
Resources
• The SICP Book “Structure and Interpretation of
Computer Programs”
• Paul Graham’s Blogs
• Clojure Home page (clojure.org)
• Clojure for the Brave and True (braveclojure.com)
• www.slideshare.net/SoumendraDaas/present
ations
• www.github.com/sdaas/clojure-talk
• https://medium.com/@sdaas/functionally-
speaking-f4dba2a1c7ee

More Related Content

What's hot

Erlang workshopdrammen
Erlang workshopdrammenErlang workshopdrammen
Erlang workshopdrammen
Reidar Sollid
 
Basics of functional Programming by Siddharth Kulkarni
Basics of functional Programming by Siddharth KulkarniBasics of functional Programming by Siddharth Kulkarni
Basics of functional Programming by Siddharth Kulkarni
Chandulal Kavar
 
Natural Language to Visualization by Neural Machine Translation
Natural Language to Visualization by Neural Machine TranslationNatural Language to Visualization by Neural Machine Translation
Natural Language to Visualization by Neural Machine Translation
ivaderivader
 
ANTLR4 and its testing
ANTLR4 and its testingANTLR4 and its testing
ANTLR4 and its testing
Knoldus Inc.
 
Technical screening .Net Developer
Technical screening  .Net DeveloperTechnical screening  .Net Developer
Technical screening .Net Developer
Tom Henricksen
 
C# 8 e além
C# 8 e alémC# 8 e além
C# 8 e além
Lucas Teles
 
Java presentation
Java presentation Java presentation
Java presentation
Md. Taiseen Azam
 
Using ANTLR on real example - convert "string combined" queries into paramete...
Using ANTLR on real example - convert "string combined" queries into paramete...Using ANTLR on real example - convert "string combined" queries into paramete...
Using ANTLR on real example - convert "string combined" queries into paramete...
Alexey Diyan
 
Craft of coding
Craft of codingCraft of coding
Craft of coding
Justin Weinberg
 
OOPS Advanced
OOPS AdvancedOOPS Advanced
OOPS Advanced
Madhavan Malolan
 
Functional OOP, Clojure style
Functional OOP, Clojure styleFunctional OOP, Clojure style
Functional OOP, Clojure style
yoavrubin
 
Xtext Webinar
Xtext WebinarXtext Webinar
Xtext Webinar
Heiko Behrens
 
Fine tuning large LMs
Fine tuning large LMsFine tuning large LMs
Fine tuning large LMs
SylvainGugger
 
Object Oriented Programming : Part 2
Object Oriented Programming : Part 2Object Oriented Programming : Part 2
Object Oriented Programming : Part 2
Madhavan Malolan
 
Writing readable Clojure code
Writing readable Clojure codeWriting readable Clojure code
Writing readable Clojure code
Jiří Knesl
 
Why Functional Programming and Clojure - LightningTalk
Why Functional Programming and Clojure - LightningTalkWhy Functional Programming and Clojure - LightningTalk
Why Functional Programming and Clojure - LightningTalk
Jakub Holy
 
Elixir Brasil 2019 - Quality: A Panacéia para seu código Elixir
Elixir Brasil 2019 - Quality:  A Panacéia para seu código ElixirElixir Brasil 2019 - Quality:  A Panacéia para seu código Elixir
Elixir Brasil 2019 - Quality: A Panacéia para seu código Elixir
Weverton Timoteo
 
Implementing DSLs in practice
Implementing DSLs in practiceImplementing DSLs in practice
Implementing DSLs in practice
Mikhail Barash
 
Class9
 Class9 Class9
Class9issbp
 
Internal domain-specific languages
Internal domain-specific languagesInternal domain-specific languages
Internal domain-specific languages
Mikhail Barash
 

What's hot (20)

Erlang workshopdrammen
Erlang workshopdrammenErlang workshopdrammen
Erlang workshopdrammen
 
Basics of functional Programming by Siddharth Kulkarni
Basics of functional Programming by Siddharth KulkarniBasics of functional Programming by Siddharth Kulkarni
Basics of functional Programming by Siddharth Kulkarni
 
Natural Language to Visualization by Neural Machine Translation
Natural Language to Visualization by Neural Machine TranslationNatural Language to Visualization by Neural Machine Translation
Natural Language to Visualization by Neural Machine Translation
 
ANTLR4 and its testing
ANTLR4 and its testingANTLR4 and its testing
ANTLR4 and its testing
 
Technical screening .Net Developer
Technical screening  .Net DeveloperTechnical screening  .Net Developer
Technical screening .Net Developer
 
C# 8 e além
C# 8 e alémC# 8 e além
C# 8 e além
 
Java presentation
Java presentation Java presentation
Java presentation
 
Using ANTLR on real example - convert "string combined" queries into paramete...
Using ANTLR on real example - convert "string combined" queries into paramete...Using ANTLR on real example - convert "string combined" queries into paramete...
Using ANTLR on real example - convert "string combined" queries into paramete...
 
Craft of coding
Craft of codingCraft of coding
Craft of coding
 
OOPS Advanced
OOPS AdvancedOOPS Advanced
OOPS Advanced
 
Functional OOP, Clojure style
Functional OOP, Clojure styleFunctional OOP, Clojure style
Functional OOP, Clojure style
 
Xtext Webinar
Xtext WebinarXtext Webinar
Xtext Webinar
 
Fine tuning large LMs
Fine tuning large LMsFine tuning large LMs
Fine tuning large LMs
 
Object Oriented Programming : Part 2
Object Oriented Programming : Part 2Object Oriented Programming : Part 2
Object Oriented Programming : Part 2
 
Writing readable Clojure code
Writing readable Clojure codeWriting readable Clojure code
Writing readable Clojure code
 
Why Functional Programming and Clojure - LightningTalk
Why Functional Programming and Clojure - LightningTalkWhy Functional Programming and Clojure - LightningTalk
Why Functional Programming and Clojure - LightningTalk
 
Elixir Brasil 2019 - Quality: A Panacéia para seu código Elixir
Elixir Brasil 2019 - Quality:  A Panacéia para seu código ElixirElixir Brasil 2019 - Quality:  A Panacéia para seu código Elixir
Elixir Brasil 2019 - Quality: A Panacéia para seu código Elixir
 
Implementing DSLs in practice
Implementing DSLs in practiceImplementing DSLs in practice
Implementing DSLs in practice
 
Class9
 Class9 Class9
Class9
 
Internal domain-specific languages
Internal domain-specific languagesInternal domain-specific languages
Internal domain-specific languages
 

Similar to Introduction to Functional Programming and Clojure

"Introduction to F#" - South Dakota Code Camp, November 5, 2011
"Introduction to F#" - South Dakota Code Camp, November 5, 2011"Introduction to F#" - South Dakota Code Camp, November 5, 2011
"Introduction to F#" - South Dakota Code Camp, November 5, 2011
Blend Interactive
 
The joy of functional programming
The joy of functional programmingThe joy of functional programming
The joy of functional programming
Steve Zhang
 
Booting into functional programming
Booting into functional programmingBooting into functional programming
Booting into functional programming
Dhaval Dalal
 
Are High Level Programming Languages for Multicore and Safety Critical Conver...
Are High Level Programming Languages for Multicore and Safety Critical Conver...Are High Level Programming Languages for Multicore and Safety Critical Conver...
Are High Level Programming Languages for Multicore and Safety Critical Conver...
InfinIT - Innovationsnetværket for it
 
Functional Python Webinar from October 22nd, 2014
Functional Python Webinar from October 22nd, 2014Functional Python Webinar from October 22nd, 2014
Functional Python Webinar from October 22nd, 2014
Reuven Lerner
 
F# for startups v2
F# for startups v2F# for startups v2
F# for startups v2
joelgrus
 
The Road to Lambda - Mike Duigou
The Road to Lambda - Mike DuigouThe Road to Lambda - Mike Duigou
The Road to Lambda - Mike Duigou
jaxconf
 
Java Closures
Java ClosuresJava Closures
Java Closures
Ben Evans
 
JSR 335 / java 8 - update reference
JSR 335 / java 8 - update referenceJSR 335 / java 8 - update reference
JSR 335 / java 8 - update reference
sandeepji_choudhary
 
F# for startups
F# for startupsF# for startups
F# for startups
joelgrus
 
The Rise of Functional Programming
The Rise of Functional ProgrammingThe Rise of Functional Programming
The Rise of Functional Programming
Tjerk Wolterink
 
Fp for the oo programmer
Fp for the oo programmerFp for the oo programmer
Fp for the oo programmer
Shawn Button
 
Clojure - An Introduction for Lisp Programmers
Clojure - An Introduction for Lisp ProgrammersClojure - An Introduction for Lisp Programmers
Clojure - An Introduction for Lisp Programmerselliando dias
 
Software Craftmanship - Cours Polytech
Software Craftmanship - Cours PolytechSoftware Craftmanship - Cours Polytech
Software Craftmanship - Cours Polytech
yannick grenzinger
 
Functional Programming for Busy Object Oriented Programmers
Functional Programming for Busy Object Oriented ProgrammersFunctional Programming for Busy Object Oriented Programmers
Functional Programming for Busy Object Oriented Programmers
Diego Freniche Brito
 
FP Days: Down the Clojure Rabbit Hole
FP Days: Down the Clojure Rabbit HoleFP Days: Down the Clojure Rabbit Hole
FP Days: Down the Clojure Rabbit HoleChristophe Grand
 
Functional-style control flow in F#
Functional-style control flow in F#Functional-style control flow in F#
Functional-style control flow in F#LincolnAtkinson
 
10 Sets of Best Practices for Java 8
10 Sets of Best Practices for Java 810 Sets of Best Practices for Java 8
10 Sets of Best Practices for Java 8
Garth Gilmour
 
Polyglot and Functional Programming (OSCON 2012)
Polyglot and Functional Programming (OSCON 2012)Polyglot and Functional Programming (OSCON 2012)
Polyglot and Functional Programming (OSCON 2012)
Martijn Verburg
 
Lec 01 introduction
Lec 01   introductionLec 01   introduction
Lec 01 introduction
UmairMuzaffar9
 

Similar to Introduction to Functional Programming and Clojure (20)

"Introduction to F#" - South Dakota Code Camp, November 5, 2011
"Introduction to F#" - South Dakota Code Camp, November 5, 2011"Introduction to F#" - South Dakota Code Camp, November 5, 2011
"Introduction to F#" - South Dakota Code Camp, November 5, 2011
 
The joy of functional programming
The joy of functional programmingThe joy of functional programming
The joy of functional programming
 
Booting into functional programming
Booting into functional programmingBooting into functional programming
Booting into functional programming
 
Are High Level Programming Languages for Multicore and Safety Critical Conver...
Are High Level Programming Languages for Multicore and Safety Critical Conver...Are High Level Programming Languages for Multicore and Safety Critical Conver...
Are High Level Programming Languages for Multicore and Safety Critical Conver...
 
Functional Python Webinar from October 22nd, 2014
Functional Python Webinar from October 22nd, 2014Functional Python Webinar from October 22nd, 2014
Functional Python Webinar from October 22nd, 2014
 
F# for startups v2
F# for startups v2F# for startups v2
F# for startups v2
 
The Road to Lambda - Mike Duigou
The Road to Lambda - Mike DuigouThe Road to Lambda - Mike Duigou
The Road to Lambda - Mike Duigou
 
Java Closures
Java ClosuresJava Closures
Java Closures
 
JSR 335 / java 8 - update reference
JSR 335 / java 8 - update referenceJSR 335 / java 8 - update reference
JSR 335 / java 8 - update reference
 
F# for startups
F# for startupsF# for startups
F# for startups
 
The Rise of Functional Programming
The Rise of Functional ProgrammingThe Rise of Functional Programming
The Rise of Functional Programming
 
Fp for the oo programmer
Fp for the oo programmerFp for the oo programmer
Fp for the oo programmer
 
Clojure - An Introduction for Lisp Programmers
Clojure - An Introduction for Lisp ProgrammersClojure - An Introduction for Lisp Programmers
Clojure - An Introduction for Lisp Programmers
 
Software Craftmanship - Cours Polytech
Software Craftmanship - Cours PolytechSoftware Craftmanship - Cours Polytech
Software Craftmanship - Cours Polytech
 
Functional Programming for Busy Object Oriented Programmers
Functional Programming for Busy Object Oriented ProgrammersFunctional Programming for Busy Object Oriented Programmers
Functional Programming for Busy Object Oriented Programmers
 
FP Days: Down the Clojure Rabbit Hole
FP Days: Down the Clojure Rabbit HoleFP Days: Down the Clojure Rabbit Hole
FP Days: Down the Clojure Rabbit Hole
 
Functional-style control flow in F#
Functional-style control flow in F#Functional-style control flow in F#
Functional-style control flow in F#
 
10 Sets of Best Practices for Java 8
10 Sets of Best Practices for Java 810 Sets of Best Practices for Java 8
10 Sets of Best Practices for Java 8
 
Polyglot and Functional Programming (OSCON 2012)
Polyglot and Functional Programming (OSCON 2012)Polyglot and Functional Programming (OSCON 2012)
Polyglot and Functional Programming (OSCON 2012)
 
Lec 01 introduction
Lec 01   introductionLec 01   introduction
Lec 01 introduction
 

Recently uploaded

Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
timtebeek1
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Globus
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
Aftab Hussain
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
takuyayamamoto1800
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
Ortus Solutions, Corp
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
Globus
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
AMB-Review
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
Philip Schwarz
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
Alina Yurenko
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
rickgrimesss22
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Globus
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
XfilesPro
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 

Recently uploaded (20)

Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 

Introduction to Functional Programming and Clojure

  • 2. What to Expect … • Look at programming in a different way – Immutable data – A world without for-loops • Understand basics of functional programming – In the context of Clojure • A POV on why to consider a functional programming style in your current project • And why Clojure might be a good choice
  • 3. What NOT to Expect … • NOT a deep dive into all aspects of the Clojure programming language • NOT about installation, debugging, performance, etc. of Clojure • NO bashing of Java or any other language • NO bashing of Object-Oriented Design
  • 4. Don’t forget Java yet … • FP is a programming paradigm or style • Some languages lend themselves better to functional programming – Clojure, Haskell, Erlang • Most languages support FP to some extent – Java 8 – JavaScript – Python
  • 5. Functional Programming Concepts • More like Mathematical Functions – vs. Subroutines/procedures • Support higher order functions • Pure functions – with no side effects • Recursion is favored over iteration • Lazy Evaluation • Referential Transparency – Once defined, a “variable” never changes value
  • 6. What is Clojure ? • Created by Rich Hickey • Immutable and Functional Programming style • Lisp that runs on the JVM • Interoperates with Java • Power of Functional Programming meets the Richness of Java Ecosystem
  • 9. Lists • Collection of heterogeneous values • Operations on lists never modify the original list. They always return a copy. • This “immutability” of data structure is a big deal in Functional Programing. • Two fundamental operators – first, & rest • Every data structure and function is built up using these two operators
  • 10. Lists
  • 11. Building Blocks – first & rest • Favoring recursion over iteration • Do you see the bomb in the nth-element ?
  • 12. Tail recursion is your friend
  • 14. Composition • FP encourages you to compose small/simpler function to create complex functions
  • 15. What does this code do ?
  • 16. Sum of square of all odd numbers .. • How testable and maintainable is this code ? • Modify this for odd numbers that aren’t multiples of 7 ? • How would this work for infinitely long data ?
  • 18. Find the first 20 prime numbers
  • 19. Laziness is good ... • Iterate : returns lazy sequence of f(x) f(f(x)) etc .. • take : returns a lazy sequence of first n from collection • Map and filter can work on lazy sequences • Check out the call to java.lang.Math.sqrt
  • 21. Reading a CSV File … FROM Smith,John,45,90210 Frank,Peter,25,90110 Bond,James,38,90110 TO {:zip 90210, :age 45, :fname "John", :lname "Smith"} {:zip 90110, :age 25, :fname "Peter", :lname "Frank"} {:zip 90110, :age 38, :fname "James", :lname "Bond"}
  • 22. 12 lines of Clojure Code …
  • 23. What the %$*&^ was that ?
  • 24. In Summary … • FP concepts can be used to create concise, highly modular, and composable code • Java 8 and JavaScript have good support for FP concepts • Clojure interoperates well with Java, and could be a good way to experiment with FP without abandoning the Java ecosystem
  • 25. Questions ? Please give your feedback at http://bit.ly/introfp
  • 26. Resources • The SICP Book “Structure and Interpretation of Computer Programs” • Paul Graham’s Blogs • Clojure Home page (clojure.org) • Clojure for the Brave and True (braveclojure.com) • www.slideshare.net/SoumendraDaas/present ations • www.github.com/sdaas/clojure-talk • https://medium.com/@sdaas/functionally- speaking-f4dba2a1c7ee