SlideShare a Scribd company logo
SWIFT
2014.7.9
bOb_sTrane@Phybbit
/ /twitter github Qiita
Swift
Swift
@bOb_sTrane(Qiita/Twitter)
Phybbit iOS /Rails
( ...) , FRP
(Lisp Scala Haskell )
SWIFT
SWIFT
1.
2.
3.
4.
// Intの引数2つを取り、和を返す関数
func add(a: Int, b: Int) -> Int{
return a + b
}
// Intの引数2つを取りIntを返す関数型を引数する関数
func someFunc(mathFunction: (Int, Int) -> Int, a: Int, b: Int) {
println(mathFunction(a, b))
}
someFunc(add, 100, 200) // 300が出力
func stepForward(input: Int) -> Int {
return input + 1
}
func stepBackward(input: Int) -> Int {
return input - 1
}
func chooseStepFunction(isBackward: Bool) -> (Int) -> Int {
return isBackward ? stepBackward : stepForward
}
var currVal = 10
let moveNearerToZero = chooseStepFunction(currVal > 0)
while currVal != 0 {
currVal = moveNearerToZero(currVal)
println(currVal) // 0まで1ずつカウントダウン
}
// 普通に定義
func greeting(name: String) {
println("Hello (name)")
}
greeting("Taro")
// 関数を変数に代入して定義
let greeting = { (name:String) -> Void in
println("Hello (name)")
}
greeting("Taro")
func chooseStepFunction(isBackward: Bool) -> (Int) -> Int {
// 関数内で関数を宣言
func stepForward(input: Int) -> Int { return input + 1 }
func stepBackward(input:Int) -> Int { return input - 1 }
return isBackward ? stepBackward : stepForward
}
var currentValue = -4
let moveNearerToZero = chooseStepFunction(currentValue > 0)
while currentValue != 0 {
currentValue = moveNearerToZero(currentValue)
println(currentValue)
}
// while currentValue != 0 {
// stepForwardがスコープ外のため実行できない
// currentValue = stepForward(currentValue)
// }
let names = ["Taro", "Jiro", "Saburo", "Shiro", "Goro"]
// 通常の定義方法
sorted(names) {(s1:String, s2:String) -> Bool in return s1 > s2 }
// [Taro, Shiro, Saburo, Jiro, Goro]
// 型推論 (sorted関数の定義から推論される)
sorted(names) { s1, s2 in return s1 > s2}
// 引数名の自動生成 & 暗示的なreturn
sorted(names) { $0 > $1 }
(Blocks )
class LeakPerson {
var name: String
@lazy var greeting: String = { return "Hello, (self.name)" }()
init(name: String) { self.name = name }
deinit { println("LeakPerson deinit called") }
}
var leakPerson: LeakPerson! = LeakPerson(name:"Leak")
println(leakPerson.greeting)
leakPerson = nil // deinitがコールされない
class Person {
var name: String
@lazy var greeting: String = { [unowned self] in return "Hello, (self.name)" }()
init(name: String) { self.name = name }
deinit { println("Person deinit called") }
}
var person: Person! = Person(name:"NotLeak")
println(person.greeting)
person = nil // deinitがコールされる
SWIFT
SWIFT
@lazy
class Person {
var name: String
@lazy var personalizedGreeting: String = {
[unowned self] in
println("heavy task started")
// Something very heavy task
for value in 0...20000000 {
if value > 10000000 && value % 100000 == 0{
println("value is (value)")
}
}
println("personalizedGreeting called")
return "Hello, (self.name)!"
}()
( )
init (name:String) {
self.name = name
println("initialized")
}
deinit {
println("destructed")
}
}
var person: Person! = Person(name: "Strange Bob")
println("person object has initialized")
println(person.personalizedGreeting)
person = nil
personalizedGreeting
Blocks
lazy
Swift
Swift --
Swift @lazy
How to do proper LazyLoadingin Swift
Learn SwiftbyrunningScripts
MemoryLeaks In The SwiftPlayground
LazyInitialization with Swift
7 1 otakyou.com
( )https://www.otakyou.com/

More Related Content

What's hot

An Intro To ES6
An Intro To ES6An Intro To ES6
An Intro To ES6
FITC
 
Type Driven Development with TypeScript
Type Driven Development with TypeScriptType Driven Development with TypeScript
Type Driven Development with TypeScript
Garth Gilmour
 
Swift Programming Language
Swift Programming LanguageSwift Programming Language
Swift Programming Language
Giuseppe Arici
 
Explaining ES6: JavaScript History and What is to Come
Explaining ES6: JavaScript History and What is to ComeExplaining ES6: JavaScript History and What is to Come
Explaining ES6: JavaScript History and What is to Come
Cory Forsyth
 
A swift introduction to Swift
A swift introduction to SwiftA swift introduction to Swift
A swift introduction to Swift
Giordano Scalzo
 
Free Monads Getting Started
Free Monads Getting StartedFree Monads Getting Started
Free Monads Getting Started
Kent Ohashi
 
"Немного о функциональном программирование в JavaScript" Алексей Коваленко
"Немного о функциональном программирование в JavaScript" Алексей Коваленко"Немного о функциональном программирование в JavaScript" Алексей Коваленко
"Немного о функциональном программирование в JavaScript" Алексей Коваленко
Fwdays
 
MP in Clojure
MP in ClojureMP in Clojure
MP in Clojure
Kent Ohashi
 
Developing iOS apps with Swift
Developing iOS apps with SwiftDeveloping iOS apps with Swift
Developing iOS apps with Swift
New Generation Applications
 
All Aboard The Scala-to-PureScript Express!
All Aboard The Scala-to-PureScript Express!All Aboard The Scala-to-PureScript Express!
All Aboard The Scala-to-PureScript Express!
John De Goes
 
Introduction to Swift programming language.
Introduction to Swift programming language.Introduction to Swift programming language.
Introduction to Swift programming language.
Icalia Labs
 
JavaScript ES6
JavaScript ES6JavaScript ES6
JavaScript ES6
Leo Hernandez
 
... now write an interpreter (PHPem 2016)
... now write an interpreter (PHPem 2016)... now write an interpreter (PHPem 2016)
... now write an interpreter (PHPem 2016)
James Titcumb
 
Swift internals
Swift internalsSwift internals
Swift internals
Jung Kim
 
Javascript ES6 generators
Javascript ES6 generatorsJavascript ES6 generators
Javascript ES6 generators
Ramesh Nair
 
Php 5.6
Php 5.6Php 5.6
Slide
SlideSlide
Swift 2
Swift 2Swift 2
Swift 2
Jens Ravens
 
The best of AltJava is Xtend
The best of AltJava is XtendThe best of AltJava is Xtend
The best of AltJava is Xtend
takezoe
 
Programming Language Swift Overview
Programming Language Swift OverviewProgramming Language Swift Overview
Programming Language Swift Overview
Kaz Yoshikawa
 

What's hot (20)

An Intro To ES6
An Intro To ES6An Intro To ES6
An Intro To ES6
 
Type Driven Development with TypeScript
Type Driven Development with TypeScriptType Driven Development with TypeScript
Type Driven Development with TypeScript
 
Swift Programming Language
Swift Programming LanguageSwift Programming Language
Swift Programming Language
 
Explaining ES6: JavaScript History and What is to Come
Explaining ES6: JavaScript History and What is to ComeExplaining ES6: JavaScript History and What is to Come
Explaining ES6: JavaScript History and What is to Come
 
A swift introduction to Swift
A swift introduction to SwiftA swift introduction to Swift
A swift introduction to Swift
 
Free Monads Getting Started
Free Monads Getting StartedFree Monads Getting Started
Free Monads Getting Started
 
"Немного о функциональном программирование в JavaScript" Алексей Коваленко
"Немного о функциональном программирование в JavaScript" Алексей Коваленко"Немного о функциональном программирование в JavaScript" Алексей Коваленко
"Немного о функциональном программирование в JavaScript" Алексей Коваленко
 
MP in Clojure
MP in ClojureMP in Clojure
MP in Clojure
 
Developing iOS apps with Swift
Developing iOS apps with SwiftDeveloping iOS apps with Swift
Developing iOS apps with Swift
 
All Aboard The Scala-to-PureScript Express!
All Aboard The Scala-to-PureScript Express!All Aboard The Scala-to-PureScript Express!
All Aboard The Scala-to-PureScript Express!
 
Introduction to Swift programming language.
Introduction to Swift programming language.Introduction to Swift programming language.
Introduction to Swift programming language.
 
JavaScript ES6
JavaScript ES6JavaScript ES6
JavaScript ES6
 
... now write an interpreter (PHPem 2016)
... now write an interpreter (PHPem 2016)... now write an interpreter (PHPem 2016)
... now write an interpreter (PHPem 2016)
 
Swift internals
Swift internalsSwift internals
Swift internals
 
Javascript ES6 generators
Javascript ES6 generatorsJavascript ES6 generators
Javascript ES6 generators
 
Php 5.6
Php 5.6Php 5.6
Php 5.6
 
Slide
SlideSlide
Slide
 
Swift 2
Swift 2Swift 2
Swift 2
 
The best of AltJava is Xtend
The best of AltJava is XtendThe best of AltJava is Xtend
The best of AltJava is Xtend
 
Programming Language Swift Overview
Programming Language Swift OverviewProgramming Language Swift Overview
Programming Language Swift Overview
 

Viewers also liked

Playing with playgrounds
Playing with playgroundsPlaying with playgrounds
Playing with playgroundsEurico Doirado
 
SwiftでSNS投稿を行う
SwiftでSNS投稿を行うSwiftでSNS投稿を行う
SwiftでSNS投稿を行う
Takashi Matsumoto
 
ミルフィーユ 自動回路設計ツール
ミルフィーユ 自動回路設計ツールミルフィーユ 自動回路設計ツール
ミルフィーユ 自動回路設計ツール
Yoshinari Kou
 
マンガ駆動開発のすゝめ
マンガ駆動開発のすゝめマンガ駆動開発のすゝめ
マンガ駆動開発のすゝめ
Kazuhide Okamura
 
マンガ駆動開発 第3版
マンガ駆動開発 第3版マンガ駆動開発 第3版
マンガ駆動開発 第3版
Koji Hara
 
継続的デリバリー全体像とハンズオン #yuru_gee #21cafe
継続的デリバリー全体像とハンズオン #yuru_gee #21cafe継続的デリバリー全体像とハンズオン #yuru_gee #21cafe
継続的デリバリー全体像とハンズオン #yuru_gee #21cafe
智治 長沢
 
Beatroboでのハードウェアプロトタイピング
BeatroboでのハードウェアプロトタイピングBeatroboでのハードウェアプロトタイピング
Beatroboでのハードウェアプロトタイピング
Hideyuki TAKEI
 
IoT超初心者がMilkcocoaからラズベリーパイに遠隔Lチカしてみた
IoT超初心者がMilkcocoaからラズベリーパイに遠隔LチカしてみたIoT超初心者がMilkcocoaからラズベリーパイに遠隔Lチカしてみた
IoT超初心者がMilkcocoaからラズベリーパイに遠隔Lチカしてみた
Kayoko Hashi
 
はじめてのMilkcocoa
はじめてのMilkcocoaはじめてのMilkcocoa
はじめてのMilkcocoa
Matsufuji Misako
 
Webデザイナになる為の3つのヒント
Webデザイナになる為の3つのヒントWebデザイナになる為の3つのヒント
Webデザイナになる為の3つのヒント
Akihiro Sato
 
ドローン + IT 〜エンジニアはフィールドに出よう〜
ドローン + IT 〜エンジニアはフィールドに出よう〜ドローン + IT 〜エンジニアはフィールドに出よう〜
ドローン + IT 〜エンジニアはフィールドに出よう〜
Tomo Watanabe
 
渋谷モノ系ミートアップ Watanabe p
渋谷モノ系ミートアップ Watanabe p渋谷モノ系ミートアップ Watanabe p
渋谷モノ系ミートアップ Watanabe p
Noboru Watanabe
 
Milkcocoa + gmaps.jsで、バーチャルサバゲを作ってみた
Milkcocoa + gmaps.jsで、バーチャルサバゲを作ってみたMilkcocoa + gmaps.jsで、バーチャルサバゲを作ってみた
Milkcocoa + gmaps.jsで、バーチャルサバゲを作ってみた
Yukiko Tamiya
 
Milkcocoa を飲んだらちょっと勇気がでた話
Milkcocoa を飲んだらちょっと勇気がでた話Milkcocoa を飲んだらちょっと勇気がでた話
Milkcocoa を飲んだらちょっと勇気がでた話
Kiyoe Furuichi
 
Neurobiology of Leela
Neurobiology of LeelaNeurobiology of Leela
Neurobiology of Leela
charinistudy
 
Album csr adirect "Sahur Goes To Panti"
Album csr adirect "Sahur Goes To Panti"Album csr adirect "Sahur Goes To Panti"
Album csr adirect "Sahur Goes To Panti"
rizkyadhechurnia
 
гордон августовскаястудия2016
гордон августовскаястудия2016гордон августовскаястудия2016
гордон августовскаястудия2016
Валерия Кулеш
 
Ecommerce in the nordics - A roadmap for success
Ecommerce in the nordics - A roadmap for successEcommerce in the nordics - A roadmap for success
Ecommerce in the nordics - A roadmap for success
Sparkow
 
Nirvana Craft Catalog
Nirvana Craft CatalogNirvana Craft Catalog
Nirvana Craft Catalog
amit_synclovis
 

Viewers also liked (20)

Playing with playgrounds
Playing with playgroundsPlaying with playgrounds
Playing with playgrounds
 
SwiftでSNS投稿を行う
SwiftでSNS投稿を行うSwiftでSNS投稿を行う
SwiftでSNS投稿を行う
 
ミルフィーユ 自動回路設計ツール
ミルフィーユ 自動回路設計ツールミルフィーユ 自動回路設計ツール
ミルフィーユ 自動回路設計ツール
 
マンガ駆動開発のすゝめ
マンガ駆動開発のすゝめマンガ駆動開発のすゝめ
マンガ駆動開発のすゝめ
 
マンガ駆動開発 第3版
マンガ駆動開発 第3版マンガ駆動開発 第3版
マンガ駆動開発 第3版
 
継続的デリバリー全体像とハンズオン #yuru_gee #21cafe
継続的デリバリー全体像とハンズオン #yuru_gee #21cafe継続的デリバリー全体像とハンズオン #yuru_gee #21cafe
継続的デリバリー全体像とハンズオン #yuru_gee #21cafe
 
Beatroboでのハードウェアプロトタイピング
BeatroboでのハードウェアプロトタイピングBeatroboでのハードウェアプロトタイピング
Beatroboでのハードウェアプロトタイピング
 
IoT超初心者がMilkcocoaからラズベリーパイに遠隔Lチカしてみた
IoT超初心者がMilkcocoaからラズベリーパイに遠隔LチカしてみたIoT超初心者がMilkcocoaからラズベリーパイに遠隔Lチカしてみた
IoT超初心者がMilkcocoaからラズベリーパイに遠隔Lチカしてみた
 
はじめてのMilkcocoa
はじめてのMilkcocoaはじめてのMilkcocoa
はじめてのMilkcocoa
 
Webデザイナになる為の3つのヒント
Webデザイナになる為の3つのヒントWebデザイナになる為の3つのヒント
Webデザイナになる為の3つのヒント
 
ドローン + IT 〜エンジニアはフィールドに出よう〜
ドローン + IT 〜エンジニアはフィールドに出よう〜ドローン + IT 〜エンジニアはフィールドに出よう〜
ドローン + IT 〜エンジニアはフィールドに出よう〜
 
渋谷モノ系ミートアップ Watanabe p
渋谷モノ系ミートアップ Watanabe p渋谷モノ系ミートアップ Watanabe p
渋谷モノ系ミートアップ Watanabe p
 
Milkcocoa + gmaps.jsで、バーチャルサバゲを作ってみた
Milkcocoa + gmaps.jsで、バーチャルサバゲを作ってみたMilkcocoa + gmaps.jsで、バーチャルサバゲを作ってみた
Milkcocoa + gmaps.jsで、バーチャルサバゲを作ってみた
 
Milkcocoa を飲んだらちょっと勇気がでた話
Milkcocoa を飲んだらちょっと勇気がでた話Milkcocoa を飲んだらちょっと勇気がでた話
Milkcocoa を飲んだらちょっと勇気がでた話
 
Neurobiology of Leela
Neurobiology of LeelaNeurobiology of Leela
Neurobiology of Leela
 
Album csr adirect "Sahur Goes To Panti"
Album csr adirect "Sahur Goes To Panti"Album csr adirect "Sahur Goes To Panti"
Album csr adirect "Sahur Goes To Panti"
 
CV Madau
CV MadauCV Madau
CV Madau
 
гордон августовскаястудия2016
гордон августовскаястудия2016гордон августовскаястудия2016
гордон августовскаястудия2016
 
Ecommerce in the nordics - A roadmap for success
Ecommerce in the nordics - A roadmap for successEcommerce in the nordics - A roadmap for success
Ecommerce in the nordics - A roadmap for success
 
Nirvana Craft Catalog
Nirvana Craft CatalogNirvana Craft Catalog
Nirvana Craft Catalog
 

Similar to Swiftの関数型っぽい部分

What's New In C# 7
What's New In C# 7What's New In C# 7
What's New In C# 7
Paulo Morgado
 
ITT 2015 - Saul Mora - Object Oriented Function Programming
ITT 2015 - Saul Mora - Object Oriented Function ProgrammingITT 2015 - Saul Mora - Object Oriented Function Programming
ITT 2015 - Saul Mora - Object Oriented Function Programming
Istanbul Tech Talks
 
Hello Swift 3/5 - Function
Hello Swift 3/5 - FunctionHello Swift 3/5 - Function
Hello Swift 3/5 - Function
Cody Yun
 
Generics and Inference
Generics and InferenceGenerics and Inference
Generics and Inference
Richard Fox
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with ClojureDmitry Buzdin
 
Scala - brief intro
Scala - brief introScala - brief intro
Scala - brief intro
Razvan Cojocaru
 
Ast transformations
Ast transformationsAst transformations
Ast transformations
HamletDRC
 
The Ring programming language version 1.7 book - Part 35 of 196
The Ring programming language version 1.7 book - Part 35 of 196The Ring programming language version 1.7 book - Part 35 of 196
The Ring programming language version 1.7 book - Part 35 of 196
Mahmoud Samir Fayed
 
Imugi: Compiler made with Python
Imugi: Compiler made with PythonImugi: Compiler made with Python
Imugi: Compiler made with Python
Han Lee
 
EcmaScript unchained
EcmaScript unchainedEcmaScript unchained
EcmaScript unchained
Eduard Tomàs
 
Kotlin For Android - Functions (part 3 of 7)
Kotlin For Android - Functions (part 3 of 7)Kotlin For Android - Functions (part 3 of 7)
Kotlin For Android - Functions (part 3 of 7)
Gesh Markov
 
Swift the implicit parts
Swift the implicit partsSwift the implicit parts
Swift the implicit partsMaxim Zaks
 
DevOps with Fabric
DevOps with FabricDevOps with Fabric
DevOps with Fabric
Simone Federici
 
Scala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecScala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecLoïc Descotte
 
AST Transformations at JFokus
AST Transformations at JFokusAST Transformations at JFokus
AST Transformations at JFokusHamletDRC
 
AST Transformations
AST TransformationsAST Transformations
AST TransformationsHamletDRC
 
Java byte code in practice
Java byte code in practiceJava byte code in practice
Java byte code in practice
Rafael Winterhalter
 
エンタープライズ・クラウドと 並列・分散・非同期処理
エンタープライズ・クラウドと 並列・分散・非同期処理エンタープライズ・クラウドと 並列・分散・非同期処理
エンタープライズ・クラウドと 並列・分散・非同期処理maruyama097
 
Poly-paradigm Java
Poly-paradigm JavaPoly-paradigm Java
Poly-paradigm Java
Pavel Tcholakov
 
Groovy grails types, operators, objects
Groovy grails types, operators, objectsGroovy grails types, operators, objects
Groovy grails types, operators, objects
Husain Dalal
 

Similar to Swiftの関数型っぽい部分 (20)

What's New In C# 7
What's New In C# 7What's New In C# 7
What's New In C# 7
 
ITT 2015 - Saul Mora - Object Oriented Function Programming
ITT 2015 - Saul Mora - Object Oriented Function ProgrammingITT 2015 - Saul Mora - Object Oriented Function Programming
ITT 2015 - Saul Mora - Object Oriented Function Programming
 
Hello Swift 3/5 - Function
Hello Swift 3/5 - FunctionHello Swift 3/5 - Function
Hello Swift 3/5 - Function
 
Generics and Inference
Generics and InferenceGenerics and Inference
Generics and Inference
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
 
Scala - brief intro
Scala - brief introScala - brief intro
Scala - brief intro
 
Ast transformations
Ast transformationsAst transformations
Ast transformations
 
The Ring programming language version 1.7 book - Part 35 of 196
The Ring programming language version 1.7 book - Part 35 of 196The Ring programming language version 1.7 book - Part 35 of 196
The Ring programming language version 1.7 book - Part 35 of 196
 
Imugi: Compiler made with Python
Imugi: Compiler made with PythonImugi: Compiler made with Python
Imugi: Compiler made with Python
 
EcmaScript unchained
EcmaScript unchainedEcmaScript unchained
EcmaScript unchained
 
Kotlin For Android - Functions (part 3 of 7)
Kotlin For Android - Functions (part 3 of 7)Kotlin For Android - Functions (part 3 of 7)
Kotlin For Android - Functions (part 3 of 7)
 
Swift the implicit parts
Swift the implicit partsSwift the implicit parts
Swift the implicit parts
 
DevOps with Fabric
DevOps with FabricDevOps with Fabric
DevOps with Fabric
 
Scala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecScala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar Prokopec
 
AST Transformations at JFokus
AST Transformations at JFokusAST Transformations at JFokus
AST Transformations at JFokus
 
AST Transformations
AST TransformationsAST Transformations
AST Transformations
 
Java byte code in practice
Java byte code in practiceJava byte code in practice
Java byte code in practice
 
エンタープライズ・クラウドと 並列・分散・非同期処理
エンタープライズ・クラウドと 並列・分散・非同期処理エンタープライズ・クラウドと 並列・分散・非同期処理
エンタープライズ・クラウドと 並列・分散・非同期処理
 
Poly-paradigm Java
Poly-paradigm JavaPoly-paradigm Java
Poly-paradigm Java
 
Groovy grails types, operators, objects
Groovy grails types, operators, objectsGroovy grails types, operators, objects
Groovy grails types, operators, objects
 

Recently uploaded

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
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 
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
 
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
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
vrstrong314
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
Juraj Vysvader
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
Globus
 
Explore Modern SharePoint Templates for 2024
Explore Modern SharePoint Templates for 2024Explore Modern SharePoint Templates for 2024
Explore Modern SharePoint Templates for 2024
Sharepoint Designs
 
Designing for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web ServicesDesigning for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web Services
KrzysztofKkol1
 
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
XfilesPro
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
Globus
 
Strategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptxStrategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptx
varshanayak241
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Anthony Dahanne
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Globus
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Globus
 
Why React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdfWhy React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdf
ayushiqss
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
WSO2
 
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
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus
 

Recently uploaded (20)

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
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
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
 
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
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
Explore Modern SharePoint Templates for 2024
Explore Modern SharePoint Templates for 2024Explore Modern SharePoint Templates for 2024
Explore Modern SharePoint Templates for 2024
 
Designing for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web ServicesDesigning for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web Services
 
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 
Strategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptxStrategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptx
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 
Why React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdfWhy React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdf
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
 
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 Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 

Swiftの関数型っぽい部分

  • 3. @bOb_sTrane(Qiita/Twitter) Phybbit iOS /Rails ( ...) , FRP (Lisp Scala Haskell )
  • 6. // Intの引数2つを取り、和を返す関数 func add(a: Int, b: Int) -> Int{ return a + b } // Intの引数2つを取りIntを返す関数型を引数する関数 func someFunc(mathFunction: (Int, Int) -> Int, a: Int, b: Int) { println(mathFunction(a, b)) } someFunc(add, 100, 200) // 300が出力
  • 7. func stepForward(input: Int) -> Int { return input + 1 } func stepBackward(input: Int) -> Int { return input - 1 } func chooseStepFunction(isBackward: Bool) -> (Int) -> Int { return isBackward ? stepBackward : stepForward } var currVal = 10 let moveNearerToZero = chooseStepFunction(currVal > 0) while currVal != 0 { currVal = moveNearerToZero(currVal) println(currVal) // 0まで1ずつカウントダウン }
  • 8. // 普通に定義 func greeting(name: String) { println("Hello (name)") } greeting("Taro") // 関数を変数に代入して定義 let greeting = { (name:String) -> Void in println("Hello (name)") } greeting("Taro")
  • 9. func chooseStepFunction(isBackward: Bool) -> (Int) -> Int { // 関数内で関数を宣言 func stepForward(input: Int) -> Int { return input + 1 } func stepBackward(input:Int) -> Int { return input - 1 } return isBackward ? stepBackward : stepForward } var currentValue = -4 let moveNearerToZero = chooseStepFunction(currentValue > 0) while currentValue != 0 { currentValue = moveNearerToZero(currentValue) println(currentValue) } // while currentValue != 0 { // stepForwardがスコープ外のため実行できない // currentValue = stepForward(currentValue) // }
  • 10. let names = ["Taro", "Jiro", "Saburo", "Shiro", "Goro"] // 通常の定義方法 sorted(names) {(s1:String, s2:String) -> Bool in return s1 > s2 } // [Taro, Shiro, Saburo, Jiro, Goro] // 型推論 (sorted関数の定義から推論される) sorted(names) { s1, s2 in return s1 > s2} // 引数名の自動生成 & 暗示的なreturn sorted(names) { $0 > $1 }
  • 11. (Blocks ) class LeakPerson { var name: String @lazy var greeting: String = { return "Hello, (self.name)" }() init(name: String) { self.name = name } deinit { println("LeakPerson deinit called") } } var leakPerson: LeakPerson! = LeakPerson(name:"Leak") println(leakPerson.greeting) leakPerson = nil // deinitがコールされない
  • 12. class Person { var name: String @lazy var greeting: String = { [unowned self] in return "Hello, (self.name)" }() init(name: String) { self.name = name } deinit { println("Person deinit called") } } var person: Person! = Person(name:"NotLeak") println(person.greeting) person = nil // deinitがコールされる
  • 13. SWIFT
  • 15. class Person { var name: String @lazy var personalizedGreeting: String = { [unowned self] in println("heavy task started") // Something very heavy task for value in 0...20000000 { if value > 10000000 && value % 100000 == 0{ println("value is (value)") } } println("personalizedGreeting called") return "Hello, (self.name)!" }()
  • 16. ( ) init (name:String) { self.name = name println("initialized") } deinit { println("destructed") } } var person: Person! = Person(name: "Strange Bob") println("person object has initialized") println(person.personalizedGreeting) person = nil personalizedGreeting
  • 18. Swift Swift -- Swift @lazy How to do proper LazyLoadingin Swift Learn SwiftbyrunningScripts MemoryLeaks In The SwiftPlayground LazyInitialization with Swift
  • 19.
  • 20. 7 1 otakyou.com ( )https://www.otakyou.com/