SlideShare a Scribd company logo
1 of 21
(fun)ctional go
First class/Pure functions
Higher Order Functions
Immutability 
(kinda)
Currying
First class functions? 
type Fi func() int 
func doThing(s string, i int, fun Fi) { 
fmt.Println(s) // ohai 
fmt.Println(i) // 42 
fmt.Println(fun) // pointer e.g. 0x2200 
fmt.Println(fun()) // 1 
} 
func main() { 
doThing("ohai", 42, func () int { return 1 }) 
}
Higher order functions?
Return other functions 
type Fi func(int) int 
func makeAdder(x int) Fi { 
return func (y int) int { 
return x + y 
} 
} 
func main() { 
add2 := makeAdder(2) 
fmt.Println(add2(1)) // 3 
fmt.Println(add2(2)) // 4 
}
Take functions as arguments 
type Fi func(int) int 
type Fii func(int, int) int 
func MakeFi(x int, fun Fii) Fi { 
return func (y int) int { 
return fun(x, y) 
} 
} 
func main() { 
even := MakeFi(2, func (x, y int) int { return x % y }) 
fmt.Println(even(1)) // 0 
fmt.Println(even(4)) // 2 
}
Pure Functions? 
Idempotent, stateless and without side effect 
// not pure 
external := 1 
func bad(i int) int { 
external = i + external // side effect and state full 
return external 
} 
fmt.Println(bad(external)) // 2 
fmt.Println(bad(external)) // 4 not idempotent 
// pure 
external := 1 
func good(x int) int { 
// only uses variables in closure 
// no side effects no state 
return x + 1 
} 
fmt.Println(good(external)) // 2 
fmt.Println(good(external)) // 2 idempotent
Immutability 
An immutable object is an object whose state cannot be 
modified after it is created.
Currying 
transforming a function that takes multiple arguments in such a way that it can
func makeAdd(a int) func(int) int { 
return func(b int) int { 
return a + b 
} 
} 
func main() { 
add2 := makeAdd(2) 
add3 := makeAdd(3) 
fmt.Println(add2(5), add3(6)) 
}
func modulo(x, y int) int { 
return x % y 
} 
func makeModulo(x int) func(int) int { 
return func(y int) int { 
return modulo(x, y) 
} 
} 
func main() { 
isOdd := makeModulo(2) 
fmt.Println(isOdd(2)) // 0 
fmt.Println(isOdd(3)) // 2 
}
How about something 
useful?
Thank you! 
Chirstan Johansen, Brian Lonsdorf and Everyone at 
UBXD

More Related Content

What's hot

Kotlin collections
Kotlin collectionsKotlin collections
Kotlin collectionsMyeongin Woo
 
Excel function
Excel functionExcel function
Excel functionSirajRock
 
Introducción a Elixir
Introducción a ElixirIntroducción a Elixir
Introducción a ElixirSvet Ivantchev
 
The Ring programming language version 1.3 book - Part 18 of 88
The Ring programming language version 1.3 book - Part 18 of 88The Ring programming language version 1.3 book - Part 18 of 88
The Ring programming language version 1.3 book - Part 18 of 88Mahmoud Samir Fayed
 
Python Programming: Data Structure
Python Programming: Data StructurePython Programming: Data Structure
Python Programming: Data StructureChan Shik Lim
 
7. inverse trig functions and linear trig equations-x
7. inverse trig functions and  linear trig equations-x7. inverse trig functions and  linear trig equations-x
7. inverse trig functions and linear trig equations-xharbormath240
 
Abstracting over Execution with Higher Kinded Types
Abstracting over Execution with Higher Kinded TypesAbstracting over Execution with Higher Kinded Types
Abstracting over Execution with Higher Kinded TypesPhilip Schwarz
 
Functional programming in Python
Functional programming in PythonFunctional programming in Python
Functional programming in PythonColin Su
 
Java interface and inheritance
Java interface and inheritanceJava interface and inheritance
Java interface and inheritanceJaromirJagr
 
Use Applicative where applicable!
Use Applicative where applicable!Use Applicative where applicable!
Use Applicative where applicable!Hermann Hueck
 
C Programming Language Part 8
C Programming Language Part 8C Programming Language Part 8
C Programming Language Part 8Rumman Ansari
 
Atomically { Delete Your Actors }
Atomically { Delete Your Actors }Atomically { Delete Your Actors }
Atomically { Delete Your Actors }John De Goes
 

What's hot (20)

Kotlin collections
Kotlin collectionsKotlin collections
Kotlin collections
 
Excel function
Excel functionExcel function
Excel function
 
functions
functionsfunctions
functions
 
FP Using ES6+ (Cheat Sheet)
FP Using ES6+ (Cheat Sheet)FP Using ES6+ (Cheat Sheet)
FP Using ES6+ (Cheat Sheet)
 
Introducción a Elixir
Introducción a ElixirIntroducción a Elixir
Introducción a Elixir
 
The Ring programming language version 1.3 book - Part 18 of 88
The Ring programming language version 1.3 book - Part 18 of 88The Ring programming language version 1.3 book - Part 18 of 88
The Ring programming language version 1.3 book - Part 18 of 88
 
Python Programming: Data Structure
Python Programming: Data StructurePython Programming: Data Structure
Python Programming: Data Structure
 
Haskell 101
Haskell 101Haskell 101
Haskell 101
 
Oop lecture9
Oop lecture9Oop lecture9
Oop lecture9
 
Talk Code
Talk CodeTalk Code
Talk Code
 
7. inverse trig functions and linear trig equations-x
7. inverse trig functions and  linear trig equations-x7. inverse trig functions and  linear trig equations-x
7. inverse trig functions and linear trig equations-x
 
Abstracting over Execution with Higher Kinded Types
Abstracting over Execution with Higher Kinded TypesAbstracting over Execution with Higher Kinded Types
Abstracting over Execution with Higher Kinded Types
 
week-15x
week-15xweek-15x
week-15x
 
FSharp Talk
FSharp TalkFSharp Talk
FSharp Talk
 
Py3k
Py3kPy3k
Py3k
 
Functional programming in Python
Functional programming in PythonFunctional programming in Python
Functional programming in Python
 
Java interface and inheritance
Java interface and inheritanceJava interface and inheritance
Java interface and inheritance
 
Use Applicative where applicable!
Use Applicative where applicable!Use Applicative where applicable!
Use Applicative where applicable!
 
C Programming Language Part 8
C Programming Language Part 8C Programming Language Part 8
C Programming Language Part 8
 
Atomically { Delete Your Actors }
Atomically { Delete Your Actors }Atomically { Delete Your Actors }
Atomically { Delete Your Actors }
 

Viewers also liked

PING PING or: "How I learned to stop worrying and love remote pairing."
PING PING or:  "How I learned to stop worrying and love remote pairing."PING PING or:  "How I learned to stop worrying and love remote pairing."
PING PING or: "How I learned to stop worrying and love remote pairing."BenJanecke
 
Uses of tmux explained
Uses of tmux explainedUses of tmux explained
Uses of tmux explainedStanislas Polu
 
How to Build a Dynamic Social Media Plan
How to Build a Dynamic Social Media PlanHow to Build a Dynamic Social Media Plan
How to Build a Dynamic Social Media PlanPost Planner
 
Learn BEM: CSS Naming Convention
Learn BEM: CSS Naming ConventionLearn BEM: CSS Naming Convention
Learn BEM: CSS Naming ConventionIn a Rocket
 
SEO: Getting Personal
SEO: Getting PersonalSEO: Getting Personal
SEO: Getting PersonalKirsty Hulse
 
Lightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika Aldaba
Lightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika AldabaLightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika Aldaba
Lightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika Aldabaux singapore
 

Viewers also liked (7)

PING PING or: "How I learned to stop worrying and love remote pairing."
PING PING or:  "How I learned to stop worrying and love remote pairing."PING PING or:  "How I learned to stop worrying and love remote pairing."
PING PING or: "How I learned to stop worrying and love remote pairing."
 
Uses of tmux explained
Uses of tmux explainedUses of tmux explained
Uses of tmux explained
 
How to Build a Dynamic Social Media Plan
How to Build a Dynamic Social Media PlanHow to Build a Dynamic Social Media Plan
How to Build a Dynamic Social Media Plan
 
Learn BEM: CSS Naming Convention
Learn BEM: CSS Naming ConventionLearn BEM: CSS Naming Convention
Learn BEM: CSS Naming Convention
 
SEO: Getting Personal
SEO: Getting PersonalSEO: Getting Personal
SEO: Getting Personal
 
Lightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika Aldaba
Lightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika AldabaLightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika Aldaba
Lightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika Aldaba
 
Succession “Losers”: What Happens to Executives Passed Over for the CEO Job?
Succession “Losers”: What Happens to Executives Passed Over for the CEO Job? Succession “Losers”: What Happens to Executives Passed Over for the CEO Job?
Succession “Losers”: What Happens to Executives Passed Over for the CEO Job?
 

Similar to (Fun)ctional go

Benginning Calculus Lecture notes 1 - functions
Benginning Calculus Lecture notes 1 - functionsBenginning Calculus Lecture notes 1 - functions
Benginning Calculus Lecture notes 1 - functionsbasyirstar
 
20181020 advanced higher-order function
20181020 advanced higher-order function20181020 advanced higher-order function
20181020 advanced higher-order functionChiwon Song
 
Something about Golang
Something about GolangSomething about Golang
Something about GolangAnton Arhipov
 
Swift Rocks #2: Going functional
Swift Rocks #2: Going functionalSwift Rocks #2: Going functional
Swift Rocks #2: Going functionalHackraft
 
Swift 3.0 で変わったところ - 厳選 13 項目 #love_swift #cswift
Swift 3.0 で変わったところ - 厳選 13 項目 #love_swift #cswiftSwift 3.0 で変わったところ - 厳選 13 項目 #love_swift #cswift
Swift 3.0 で変わったところ - 厳選 13 項目 #love_swift #cswiftTomohiro Kumagai
 
Swift 3.0 の新しい機能(のうちの9つ)
Swift 3.0 の新しい機能(のうちの9つ)Swift 3.0 の新しい機能(のうちの9つ)
Swift 3.0 の新しい機能(のうちの9つ)Tomohiro Kumagai
 
Introductory part of function for class 12th JEE
Introductory part of function for class 12th JEEIntroductory part of function for class 12th JEE
Introductory part of function for class 12th JEEMohanSonawane
 
Golang and Eco-System Introduction / Overview
Golang and Eco-System Introduction / OverviewGolang and Eco-System Introduction / Overview
Golang and Eco-System Introduction / OverviewMarkus Schneider
 
composite-functions.ppt
composite-functions.pptcomposite-functions.ppt
composite-functions.pptGeraldoCaamic3
 
バイオインフォ分野におけるtidyなデータ解析の最新動向
バイオインフォ分野におけるtidyなデータ解析の最新動向バイオインフォ分野におけるtidyなデータ解析の最新動向
バイオインフォ分野におけるtidyなデータ解析の最新動向弘毅 露崎
 
10〜30分で何となく分かるGo
10〜30分で何となく分かるGo10〜30分で何となく分かるGo
10〜30分で何となく分かるGoMoriyoshi Koizumi
 
3 kotlin vs. java- what kotlin has that java does not
3  kotlin vs. java- what kotlin has that java does not3  kotlin vs. java- what kotlin has that java does not
3 kotlin vs. java- what kotlin has that java does notSergey Bandysik
 
7 Python udf.pptx
7 Python udf.pptx7 Python udf.pptx
7 Python udf.pptxSUJALORAON
 
Go: It's Not Just For Google
Go: It's Not Just For GoogleGo: It's Not Just For Google
Go: It's Not Just For GoogleEleanor McHugh
 
Dti2143 chapter 5
Dti2143 chapter 5Dti2143 chapter 5
Dti2143 chapter 5alish sha
 
The following is the (incomplete) header file for the class Fracti.pdf
The following is the (incomplete) header file for the class Fracti.pdfThe following is the (incomplete) header file for the class Fracti.pdf
The following is the (incomplete) header file for the class Fracti.pdf4babies2010
 
Stanfy MadCode Meetup #9: Functional Programming 101 with Swift
Stanfy MadCode Meetup #9: Functional Programming 101 with SwiftStanfy MadCode Meetup #9: Functional Programming 101 with Swift
Stanfy MadCode Meetup #9: Functional Programming 101 with SwiftStanfy
 

Similar to (Fun)ctional go (20)

Benginning Calculus Lecture notes 1 - functions
Benginning Calculus Lecture notes 1 - functionsBenginning Calculus Lecture notes 1 - functions
Benginning Calculus Lecture notes 1 - functions
 
20181020 advanced higher-order function
20181020 advanced higher-order function20181020 advanced higher-order function
20181020 advanced higher-order function
 
Functions & Recursion
Functions & RecursionFunctions & Recursion
Functions & Recursion
 
Something about Golang
Something about GolangSomething about Golang
Something about Golang
 
6. function
6. function6. function
6. function
 
Swift Rocks #2: Going functional
Swift Rocks #2: Going functionalSwift Rocks #2: Going functional
Swift Rocks #2: Going functional
 
Swift 3.0 で変わったところ - 厳選 13 項目 #love_swift #cswift
Swift 3.0 で変わったところ - 厳選 13 項目 #love_swift #cswiftSwift 3.0 で変わったところ - 厳選 13 項目 #love_swift #cswift
Swift 3.0 で変わったところ - 厳選 13 項目 #love_swift #cswift
 
Swift 3.0 の新しい機能(のうちの9つ)
Swift 3.0 の新しい機能(のうちの9つ)Swift 3.0 の新しい機能(のうちの9つ)
Swift 3.0 の新しい機能(のうちの9つ)
 
Introductory part of function for class 12th JEE
Introductory part of function for class 12th JEEIntroductory part of function for class 12th JEE
Introductory part of function for class 12th JEE
 
Golang and Eco-System Introduction / Overview
Golang and Eco-System Introduction / OverviewGolang and Eco-System Introduction / Overview
Golang and Eco-System Introduction / Overview
 
composite-functions.ppt
composite-functions.pptcomposite-functions.ppt
composite-functions.ppt
 
バイオインフォ分野におけるtidyなデータ解析の最新動向
バイオインフォ分野におけるtidyなデータ解析の最新動向バイオインフォ分野におけるtidyなデータ解析の最新動向
バイオインフォ分野におけるtidyなデータ解析の最新動向
 
10〜30分で何となく分かるGo
10〜30分で何となく分かるGo10〜30分で何となく分かるGo
10〜30分で何となく分かるGo
 
3 kotlin vs. java- what kotlin has that java does not
3  kotlin vs. java- what kotlin has that java does not3  kotlin vs. java- what kotlin has that java does not
3 kotlin vs. java- what kotlin has that java does not
 
7 Python udf.pptx
7 Python udf.pptx7 Python udf.pptx
7 Python udf.pptx
 
Go: It's Not Just For Google
Go: It's Not Just For GoogleGo: It's Not Just For Google
Go: It's Not Just For Google
 
Fun with functions
Fun with functionsFun with functions
Fun with functions
 
Dti2143 chapter 5
Dti2143 chapter 5Dti2143 chapter 5
Dti2143 chapter 5
 
The following is the (incomplete) header file for the class Fracti.pdf
The following is the (incomplete) header file for the class Fracti.pdfThe following is the (incomplete) header file for the class Fracti.pdf
The following is the (incomplete) header file for the class Fracti.pdf
 
Stanfy MadCode Meetup #9: Functional Programming 101 with Swift
Stanfy MadCode Meetup #9: Functional Programming 101 with SwiftStanfy MadCode Meetup #9: Functional Programming 101 with Swift
Stanfy MadCode Meetup #9: Functional Programming 101 with Swift
 

Recently uploaded

BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsMehedi Hasan Shohan
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...aditisharan08
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningVitsRangannavar
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 

Recently uploaded (20)

BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software Solutions
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learning
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 

(Fun)ctional go

  • 2.
  • 7.
  • 8.
  • 9. First class functions? type Fi func() int func doThing(s string, i int, fun Fi) { fmt.Println(s) // ohai fmt.Println(i) // 42 fmt.Println(fun) // pointer e.g. 0x2200 fmt.Println(fun()) // 1 } func main() { doThing("ohai", 42, func () int { return 1 }) }
  • 11. Return other functions type Fi func(int) int func makeAdder(x int) Fi { return func (y int) int { return x + y } } func main() { add2 := makeAdder(2) fmt.Println(add2(1)) // 3 fmt.Println(add2(2)) // 4 }
  • 12. Take functions as arguments type Fi func(int) int type Fii func(int, int) int func MakeFi(x int, fun Fii) Fi { return func (y int) int { return fun(x, y) } } func main() { even := MakeFi(2, func (x, y int) int { return x % y }) fmt.Println(even(1)) // 0 fmt.Println(even(4)) // 2 }
  • 13. Pure Functions? Idempotent, stateless and without side effect // not pure external := 1 func bad(i int) int { external = i + external // side effect and state full return external } fmt.Println(bad(external)) // 2 fmt.Println(bad(external)) // 4 not idempotent // pure external := 1 func good(x int) int { // only uses variables in closure // no side effects no state return x + 1 } fmt.Println(good(external)) // 2 fmt.Println(good(external)) // 2 idempotent
  • 14. Immutability An immutable object is an object whose state cannot be modified after it is created.
  • 15. Currying transforming a function that takes multiple arguments in such a way that it can
  • 16. func makeAdd(a int) func(int) int { return func(b int) int { return a + b } } func main() { add2 := makeAdd(2) add3 := makeAdd(3) fmt.Println(add2(5), add3(6)) }
  • 17. func modulo(x, y int) int { return x % y } func makeModulo(x int) func(int) int { return func(y int) int { return modulo(x, y) } } func main() { isOdd := makeModulo(2) fmt.Println(isOdd(2)) // 0 fmt.Println(isOdd(3)) // 2 }
  • 19.
  • 20.
  • 21. Thank you! Chirstan Johansen, Brian Lonsdorf and Everyone at UBXD