SlideShare a Scribd company logo
Closure
First Class Function
func toStr(x: Int) -> String {
return "(x)"
}
toStr(3)
// functions can be assigned to a variable.
let toStr2 = {
(x: Int) -> String in
return "(x)"
}
toStr2(4)
Syntax Sugar
Pass a function as a parameter
let toStr = {
(x: Int) -> String in
return "(x)"
}
let toStr2 = {
(x: Int) -> String in
return "a(x)"
}
toStr(5)
toStr2(5)
func ajax(callback: (x: Int) -> String) {
callback(x: 10)
}
ajax(toStr) // 10
ajax(toStr2) // a10
type of the function

((x:Int) -> String)
lambda calculas
ajax({(param: Int) -> String in
return “(param)”
})
ajax({(param: Int) -> String in
return “($0)”
})
ajax({(param: Int) -> String in
return “($0)”
})
ajax(){“($0)”}
Complete
Short Hand
Closure
var result = 0 // caller’s result
ajax({
result++
})
func ajax(callback: ()->()) {
var result = 10 // nothing to do with the caller’s result
callback()
callback()
}
println(result) // 2, not 12
Callback
var result: String
ajax(
{
result = $0
},
fail:{
result = “NG”
}
)
func ajax(ok: (x:String)->(), fail fail:()->()) {
if let ret = get_string_via_ajax()
{
ok(x:ret)
} else {
fail()
}
}
map (transformer)
let list = [1, 2, 3]
list.map({$0 x 3}) // [3, 6, 9]
list.map(){$0 x 3}
list.map{$0 x 3}

More Related Content

What's hot

The Ring programming language version 1.5.2 book - Part 33 of 181
The Ring programming language version 1.5.2 book - Part 33 of 181The Ring programming language version 1.5.2 book - Part 33 of 181
The Ring programming language version 1.5.2 book - Part 33 of 181
Mahmoud Samir Fayed
 
multiple linear regression
multiple linear regressionmultiple linear regression
multiple linear regression
Akhilesh Joshi
 
アプリカティブファンクターとHaskell 2014版
アプリカティブファンクターとHaskell 2014版アプリカティブファンクターとHaskell 2014版
アプリカティブファンクターとHaskell 2014版
infinite_loop
 
Humble introduction to category theory in haskell
Humble introduction to category theory in haskellHumble introduction to category theory in haskell
Humble introduction to category theory in haskell
Jongsoo Lee
 
하스켈 프로그래밍 입문 4
하스켈 프로그래밍 입문 4하스켈 프로그래밍 입문 4
하스켈 프로그래밍 입문 4
Kwang Yul Seo
 
week-14x
week-14xweek-14x
support vector regression
support vector regressionsupport vector regression
support vector regression
Akhilesh Joshi
 
Matlab
MatlabMatlab
polynomial linear regression
polynomial linear regressionpolynomial linear regression
polynomial linear regression
Akhilesh Joshi
 
하스켈 프로그래밍 입문 3
하스켈 프로그래밍 입문 3하스켈 프로그래밍 입문 3
하스켈 프로그래밍 입문 3
Kwang Yul Seo
 
My sql command line client
My sql command line clientMy sql command line client
My sql command line client
Egerton University
 
Swift 함수 커링 사용하기
Swift 함수 커링 사용하기Swift 함수 커링 사용하기
Swift 함수 커링 사용하기
진성 오
 
Parsec
ParsecParsec
Parsec
Phil Freeman
 
logistic regression with python and R
logistic regression with python and Rlogistic regression with python and R
logistic regression with python and R
Akhilesh Joshi
 
08. haskell Functions
08. haskell Functions08. haskell Functions
08. haskell Functions
Sebastian Rettig
 
Programming in lua STRING AND ARRAY
Programming in lua STRING AND ARRAYProgramming in lua STRING AND ARRAY
Programming in lua STRING AND ARRAY
vikram mahendra
 
knn classification
knn classificationknn classification
knn classification
Akhilesh Joshi
 
Functional Javascript, CVjs
Functional Javascript, CVjsFunctional Javascript, CVjs
Functional Javascript, CVjs
kaw2
 
Akka streams vs spark structured streaming
Akka streams vs spark structured streamingAkka streams vs spark structured streaming
Akka streams vs spark structured streaming
株式会社ジオロジック
 
Introduction to Monads in Scala (1)
Introduction to Monads in Scala (1)Introduction to Monads in Scala (1)
Introduction to Monads in Scala (1)
stasimus
 

What's hot (20)

The Ring programming language version 1.5.2 book - Part 33 of 181
The Ring programming language version 1.5.2 book - Part 33 of 181The Ring programming language version 1.5.2 book - Part 33 of 181
The Ring programming language version 1.5.2 book - Part 33 of 181
 
multiple linear regression
multiple linear regressionmultiple linear regression
multiple linear regression
 
アプリカティブファンクターとHaskell 2014版
アプリカティブファンクターとHaskell 2014版アプリカティブファンクターとHaskell 2014版
アプリカティブファンクターとHaskell 2014版
 
Humble introduction to category theory in haskell
Humble introduction to category theory in haskellHumble introduction to category theory in haskell
Humble introduction to category theory in haskell
 
하스켈 프로그래밍 입문 4
하스켈 프로그래밍 입문 4하스켈 프로그래밍 입문 4
하스켈 프로그래밍 입문 4
 
week-14x
week-14xweek-14x
week-14x
 
support vector regression
support vector regressionsupport vector regression
support vector regression
 
Matlab
MatlabMatlab
Matlab
 
polynomial linear regression
polynomial linear regressionpolynomial linear regression
polynomial linear regression
 
하스켈 프로그래밍 입문 3
하스켈 프로그래밍 입문 3하스켈 프로그래밍 입문 3
하스켈 프로그래밍 입문 3
 
My sql command line client
My sql command line clientMy sql command line client
My sql command line client
 
Swift 함수 커링 사용하기
Swift 함수 커링 사용하기Swift 함수 커링 사용하기
Swift 함수 커링 사용하기
 
Parsec
ParsecParsec
Parsec
 
logistic regression with python and R
logistic regression with python and Rlogistic regression with python and R
logistic regression with python and R
 
08. haskell Functions
08. haskell Functions08. haskell Functions
08. haskell Functions
 
Programming in lua STRING AND ARRAY
Programming in lua STRING AND ARRAYProgramming in lua STRING AND ARRAY
Programming in lua STRING AND ARRAY
 
knn classification
knn classificationknn classification
knn classification
 
Functional Javascript, CVjs
Functional Javascript, CVjsFunctional Javascript, CVjs
Functional Javascript, CVjs
 
Akka streams vs spark structured streaming
Akka streams vs spark structured streamingAkka streams vs spark structured streaming
Akka streams vs spark structured streaming
 
Introduction to Monads in Scala (1)
Introduction to Monads in Scala (1)Introduction to Monads in Scala (1)
Introduction to Monads in Scala (1)
 

Viewers also liked

Process of Magazine Making
Process of Magazine MakingProcess of Magazine Making
Process of Magazine Making
DIDI1998sdf
 
2558 project
2558 project 2558 project
2558 project
TATThanaporn
 
The Top Attractions in Los Angeles
The Top Attractions in Los AngelesThe Top Attractions in Los Angeles
The Top Attractions in Los Angeles
49ThingstoDo
 
M.Safeer Durrani final cv
M.Safeer Durrani final cvM.Safeer Durrani final cv
M.Safeer Durrani final cv
Safeer Khan Durrani
 
Aws(sdk)
Aws(sdk)Aws(sdk)
Aws(sdk)
Futada Takashi
 
Coffee script
Coffee scriptCoffee script
Coffee script
Futada Takashi
 
Fms solutii externalizare mng ro
Fms solutii externalizare mng roFms solutii externalizare mng ro
Fms solutii externalizare mng ro
Razvan CALOTA
 
importance of proofreaders in translation company
importance of proofreaders in translation companyimportance of proofreaders in translation company
importance of proofreaders in translation company
lee shin
 
Untitled 2
Untitled 2Untitled 2
Untitled 2
DIDI1998sdf
 
Oates 501(c)(3) press.pptx
Oates 501(c)(3) press.pptxOates 501(c)(3) press.pptx
Oates 501(c)(3) press.pptx
Scott Oates
 
A Summary of the US Economy through Corporate Finance
A Summary of the US Economy through Corporate FinanceA Summary of the US Economy through Corporate Finance
A Summary of the US Economy through Corporate Finance
Pranav Ghai
 
My life project freddy
My life project freddyMy life project freddy
My life project freddy
fredyjairp20
 

Viewers also liked (12)

Process of Magazine Making
Process of Magazine MakingProcess of Magazine Making
Process of Magazine Making
 
2558 project
2558 project 2558 project
2558 project
 
The Top Attractions in Los Angeles
The Top Attractions in Los AngelesThe Top Attractions in Los Angeles
The Top Attractions in Los Angeles
 
M.Safeer Durrani final cv
M.Safeer Durrani final cvM.Safeer Durrani final cv
M.Safeer Durrani final cv
 
Aws(sdk)
Aws(sdk)Aws(sdk)
Aws(sdk)
 
Coffee script
Coffee scriptCoffee script
Coffee script
 
Fms solutii externalizare mng ro
Fms solutii externalizare mng roFms solutii externalizare mng ro
Fms solutii externalizare mng ro
 
importance of proofreaders in translation company
importance of proofreaders in translation companyimportance of proofreaders in translation company
importance of proofreaders in translation company
 
Untitled 2
Untitled 2Untitled 2
Untitled 2
 
Oates 501(c)(3) press.pptx
Oates 501(c)(3) press.pptxOates 501(c)(3) press.pptx
Oates 501(c)(3) press.pptx
 
A Summary of the US Economy through Corporate Finance
A Summary of the US Economy through Corporate FinanceA Summary of the US Economy through Corporate Finance
A Summary of the US Economy through Corporate Finance
 
My life project freddy
My life project freddyMy life project freddy
My life project freddy
 

Similar to Swift study: Closure

Swift the implicit parts
Swift the implicit partsSwift the implicit parts
Swift the implicit parts
Maxim Zaks
 
Millionways
MillionwaysMillionways
Millionways
Brian Lonsdorf
 
TI1220 Lecture 6: First-class Functions
TI1220 Lecture 6: First-class FunctionsTI1220 Lecture 6: First-class Functions
TI1220 Lecture 6: First-class Functions
Eelco Visser
 
Kotlin Advanced - Apalon Kotlin Sprint Part 3
Kotlin Advanced - Apalon Kotlin Sprint Part 3Kotlin Advanced - Apalon Kotlin Sprint Part 3
Kotlin Advanced - Apalon Kotlin Sprint Part 3
Kirill Rozov
 
Funcitonal Swift Conference: The Functional Way
Funcitonal Swift Conference: The Functional WayFuncitonal Swift Conference: The Functional Way
Funcitonal Swift Conference: The Functional Way
Natasha Murashev
 
Functional programming ii
Functional programming iiFunctional programming ii
Functional programming ii
Prashant Kalkar
 
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
Stanfy
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
Aleksandar Prokopec
 
ハイブリッド言語Scalaを使う
ハイブリッド言語Scalaを使うハイブリッド言語Scalaを使う
ハイブリッド言語Scalaを使う
bpstudy
 
Swift Rocks #2: Going functional
Swift Rocks #2: Going functionalSwift Rocks #2: Going functional
Swift Rocks #2: Going functional
Hackraft
 
Scala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecScala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar Prokopec
Loïc Descotte
 
Java and XML Schema
Java and XML SchemaJava and XML Schema
Java and XML Schema
Raji Ghawi
 
Functions In Scala
Functions In Scala Functions In Scala
Functions In Scala
Knoldus Inc.
 
Go ahead, make my day
Go ahead, make my dayGo ahead, make my day
Go ahead, make my day
Tor Ivry
 
A brief introduction to apply functions
A brief introduction to apply functionsA brief introduction to apply functions
A brief introduction to apply functions
NIKET CHAURASIA
 
Hitchhiker's Guide to Functional Programming
Hitchhiker's Guide to Functional ProgrammingHitchhiker's Guide to Functional Programming
Hitchhiker's Guide to Functional Programming
Sergey Shishkin
 
Redux Sagas - React Alicante
Redux Sagas - React AlicanteRedux Sagas - React Alicante
Redux Sagas - React Alicante
Ignacio Martín
 
Greyhound - Powerful Pure Functional Kafka Library - Scala Love in the City
Greyhound - Powerful Pure Functional Kafka Library - Scala Love in the CityGreyhound - Powerful Pure Functional Kafka Library - Scala Love in the City
Greyhound - Powerful Pure Functional Kafka Library - Scala Love in the City
Natan Silnitsky
 
Monadologie
MonadologieMonadologie
Monadologie
league
 
GeoGebra JavaScript CheatSheet
GeoGebra JavaScript CheatSheetGeoGebra JavaScript CheatSheet
GeoGebra JavaScript CheatSheet
Jose Perez
 

Similar to Swift study: Closure (20)

Swift the implicit parts
Swift the implicit partsSwift the implicit parts
Swift the implicit parts
 
Millionways
MillionwaysMillionways
Millionways
 
TI1220 Lecture 6: First-class Functions
TI1220 Lecture 6: First-class FunctionsTI1220 Lecture 6: First-class Functions
TI1220 Lecture 6: First-class Functions
 
Kotlin Advanced - Apalon Kotlin Sprint Part 3
Kotlin Advanced - Apalon Kotlin Sprint Part 3Kotlin Advanced - Apalon Kotlin Sprint Part 3
Kotlin Advanced - Apalon Kotlin Sprint Part 3
 
Funcitonal Swift Conference: The Functional Way
Funcitonal Swift Conference: The Functional WayFuncitonal Swift Conference: The Functional Way
Funcitonal Swift Conference: The Functional Way
 
Functional programming ii
Functional programming iiFunctional programming ii
Functional programming ii
 
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
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
ハイブリッド言語Scalaを使う
ハイブリッド言語Scalaを使うハイブリッド言語Scalaを使う
ハイブリッド言語Scalaを使う
 
Swift Rocks #2: Going functional
Swift Rocks #2: Going functionalSwift Rocks #2: Going functional
Swift Rocks #2: Going functional
 
Scala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecScala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar Prokopec
 
Java and XML Schema
Java and XML SchemaJava and XML Schema
Java and XML Schema
 
Functions In Scala
Functions In Scala Functions In Scala
Functions In Scala
 
Go ahead, make my day
Go ahead, make my dayGo ahead, make my day
Go ahead, make my day
 
A brief introduction to apply functions
A brief introduction to apply functionsA brief introduction to apply functions
A brief introduction to apply functions
 
Hitchhiker's Guide to Functional Programming
Hitchhiker's Guide to Functional ProgrammingHitchhiker's Guide to Functional Programming
Hitchhiker's Guide to Functional Programming
 
Redux Sagas - React Alicante
Redux Sagas - React AlicanteRedux Sagas - React Alicante
Redux Sagas - React Alicante
 
Greyhound - Powerful Pure Functional Kafka Library - Scala Love in the City
Greyhound - Powerful Pure Functional Kafka Library - Scala Love in the CityGreyhound - Powerful Pure Functional Kafka Library - Scala Love in the City
Greyhound - Powerful Pure Functional Kafka Library - Scala Love in the City
 
Monadologie
MonadologieMonadologie
Monadologie
 
GeoGebra JavaScript CheatSheet
GeoGebra JavaScript CheatSheetGeoGebra JavaScript CheatSheet
GeoGebra JavaScript CheatSheet
 

More from Futada Takashi

ES6 ECMA2015
ES6 ECMA2015ES6 ECMA2015
ES6 ECMA2015
Futada Takashi
 
Swift
SwiftSwift
Objective c(lang)
Objective c(lang)Objective c(lang)
Objective c(lang)
Futada Takashi
 
Aws(sns)
Aws(sns)Aws(sns)
Aws(sns)
Futada Takashi
 
Ionic2
Ionic2Ionic2
Ionic3
Ionic3Ionic3
Ionic
IonicIonic
Node js
Node jsNode js
Aws
AwsAws
Scala
ScalaScala
Java8
Java8Java8
Ruby
RubyRuby
Python
PythonPython
Golang
GolangGolang
Bootstrap
BootstrapBootstrap
Bootstrap
Futada Takashi
 
AngularJS
AngularJSAngularJS
AngularJS
Futada Takashi
 
English
EnglishEnglish
Swift study: iBeacon
Swift study: iBeaconSwift study: iBeacon
Swift study: iBeacon
Futada Takashi
 
Swift Map
Swift MapSwift Map
Swift Map
Futada Takashi
 
Swf2 ui
Swf2 uiSwf2 ui

More from Futada Takashi (20)

ES6 ECMA2015
ES6 ECMA2015ES6 ECMA2015
ES6 ECMA2015
 
Swift
SwiftSwift
Swift
 
Objective c(lang)
Objective c(lang)Objective c(lang)
Objective c(lang)
 
Aws(sns)
Aws(sns)Aws(sns)
Aws(sns)
 
Ionic2
Ionic2Ionic2
Ionic2
 
Ionic3
Ionic3Ionic3
Ionic3
 
Ionic
IonicIonic
Ionic
 
Node js
Node jsNode js
Node js
 
Aws
AwsAws
Aws
 
Scala
ScalaScala
Scala
 
Java8
Java8Java8
Java8
 
Ruby
RubyRuby
Ruby
 
Python
PythonPython
Python
 
Golang
GolangGolang
Golang
 
Bootstrap
BootstrapBootstrap
Bootstrap
 
AngularJS
AngularJSAngularJS
AngularJS
 
English
EnglishEnglish
English
 
Swift study: iBeacon
Swift study: iBeaconSwift study: iBeacon
Swift study: iBeacon
 
Swift Map
Swift MapSwift Map
Swift Map
 
Swf2 ui
Swf2 uiSwf2 ui
Swf2 ui
 

Recently uploaded

UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
Peter Muessig
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
TheSMSPoint
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
Quickdice ERP
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
mz5nrf0n
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
Drona Infotech
 
Oracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptxOracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptx
Remote DBA Services
 
Mobile app Development Services | Drona Infotech
Mobile app Development Services  | Drona InfotechMobile app Development Services  | Drona Infotech
Mobile app Development Services | Drona Infotech
Drona Infotech
 
316895207-SAP-Oil-and-Gas-Downstream-Training.pptx
316895207-SAP-Oil-and-Gas-Downstream-Training.pptx316895207-SAP-Oil-and-Gas-Downstream-Training.pptx
316895207-SAP-Oil-and-Gas-Downstream-Training.pptx
ssuserad3af4
 
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
Bert Jan Schrijver
 
Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !
Marcin Chrost
 
Modelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - AmsterdamModelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - Amsterdam
Alberto Brandolini
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
Hornet Dynamics
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
Peter Muessig
 
socradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdfsocradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdf
SOCRadar
 
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdfTop Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
VALiNTRY360
 
Top 9 Trends in Cybersecurity for 2024.pptx
Top 9 Trends in Cybersecurity for 2024.pptxTop 9 Trends in Cybersecurity for 2024.pptx
Top 9 Trends in Cybersecurity for 2024.pptx
devvsandy
 
Unveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdfUnveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdf
brainerhub1
 
Lecture 2 - software testing SE 412.pptx
Lecture 2 - software testing SE 412.pptxLecture 2 - software testing SE 412.pptx
Lecture 2 - software testing SE 412.pptx
TaghreedAltamimi
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
Grant Fritchey
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
Łukasz Chruściel
 

Recently uploaded (20)

UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
 
Oracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptxOracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptx
 
Mobile app Development Services | Drona Infotech
Mobile app Development Services  | Drona InfotechMobile app Development Services  | Drona Infotech
Mobile app Development Services | Drona Infotech
 
316895207-SAP-Oil-and-Gas-Downstream-Training.pptx
316895207-SAP-Oil-and-Gas-Downstream-Training.pptx316895207-SAP-Oil-and-Gas-Downstream-Training.pptx
316895207-SAP-Oil-and-Gas-Downstream-Training.pptx
 
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
 
Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !
 
Modelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - AmsterdamModelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - Amsterdam
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
 
socradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdfsocradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdf
 
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdfTop Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
 
Top 9 Trends in Cybersecurity for 2024.pptx
Top 9 Trends in Cybersecurity for 2024.pptxTop 9 Trends in Cybersecurity for 2024.pptx
Top 9 Trends in Cybersecurity for 2024.pptx
 
Unveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdfUnveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdf
 
Lecture 2 - software testing SE 412.pptx
Lecture 2 - software testing SE 412.pptxLecture 2 - software testing SE 412.pptx
Lecture 2 - software testing SE 412.pptx
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
 

Swift study: Closure

  • 2. First Class Function func toStr(x: Int) -> String { return "(x)" } toStr(3) // functions can be assigned to a variable. let toStr2 = { (x: Int) -> String in return "(x)" } toStr2(4) Syntax Sugar
  • 3. Pass a function as a parameter let toStr = { (x: Int) -> String in return "(x)" } let toStr2 = { (x: Int) -> String in return "a(x)" } toStr(5) toStr2(5) func ajax(callback: (x: Int) -> String) { callback(x: 10) } ajax(toStr) // 10 ajax(toStr2) // a10 type of the function ((x:Int) -> String)
  • 4. lambda calculas ajax({(param: Int) -> String in return “(param)” }) ajax({(param: Int) -> String in return “($0)” }) ajax({(param: Int) -> String in return “($0)” }) ajax(){“($0)”} Complete Short Hand
  • 5. Closure var result = 0 // caller’s result ajax({ result++ }) func ajax(callback: ()->()) { var result = 10 // nothing to do with the caller’s result callback() callback() } println(result) // 2, not 12
  • 6. Callback var result: String ajax( { result = $0 }, fail:{ result = “NG” } ) func ajax(ok: (x:String)->(), fail fail:()->()) { if let ret = get_string_via_ajax() { ok(x:ret) } else { fail() } }
  • 7. map (transformer) let list = [1, 2, 3] list.map({$0 x 3}) // [3, 6, 9] list.map(){$0 x 3} list.map{$0 x 3}