SlideShare a Scribd company logo
Ra c
) /
ED D
(-) / ) -
G I ED D
E
var number = 100
mysteryJob()
print(number)
let number = 100
mysteryJob()
print(number)
D DI
var number = 100
mysteryJob()
print(number)
// ?
let number = 100
mysteryJob()
print(number)
// 100
mutable immutable
F
var condition: Bool = true
if condition {
// true
} else {
// false
}
let condition: Bool = true
// case true
mutable immutable
F
var condition: Bool = true
var condition2: Bool = false
if condition {
if condition2 {
// true && true
} else {
// true && false
}
} else {
if condition2 {
// false && true
} else {
// false && false
}
}
let condition: Bool = true
let condition2: Bool = false
// case true && false
mutable immutable
F
var condition: Bool = true
var condition2: Bool = false
var condition3: Bool = false
if condition {
if condition2 {
if condition3 {
// true && true && true
} else {
// true && true && false
}
} else {
if condition3 {
// true && false && true
} else {
// true && false && false
}
}
} else {
if condition2 {
if condition3 {
// false && true && true
} else {
// false && true && false
}
} else {
if condition3 {
// false && false && true
} else {
// false && false && false
}
}
}
let condition: Bool = true
let condition2: Bool = false
let condition2: Bool = false
// case true && false && false
mutable immutable
/ D
Data
Program Program Program Program
Data
Program Program Program Program
mutable immutable
D C
mutable immutable
struct Hero {
var name : String
var nickname: String
}
var hero = Hero(name: "Steve Rogers",
nickname: "Captain America")
print(hero)
//Hero(name: "Steve Rogers",
nickname: "Captain America")
hero.nickname = "First Avenger"
print(hero)
//Hero(name: "Steve Rogers",
nickname: "First Avengers")
struct Hero {
var name : String
var nickname: String
}
let hero = Hero(name: "Steve Rogers",
nickname: "Captain America")
print(hero)
//Hero(name: "Steve Rogers",
nickname: "Captain America")
let captain = Hero(name: hero.name,
nickname: "First Avenger")
print(hero)
//Hero(name: "Steve Rogers",
nickname: "Captain America")
print(captain)
//Hero(name: "Steve Rogers",
nickname: "First Avengers")
ED D
1. Predictable

2. Testability

3. Thread-Safe
Maintainable
}
4. Unfamiliar

5. Memory wasting

6. Low performance

( in some case )
ED FC ED D
Maintenance
Performance
vs
ECF EC EC
Data
feature
AI
struct Hero {
var name: String
var nickname: String
}
let hero = Hero(name: "Steve Rogers",
nickname: "Captain America")
var captain = hero
captain.nickname = "First Avenger" Copy On Write
HD C
protocol Mappable {
func map<U>(_ f: (Self) -> U) -> U
}
extension Mappable {
func map<U>(_ f: (Self) -> U) -> U {
return f(self)
}
}
extension Hero: Mappable { }
let hero = Hero(name: "Steve Rogers",
nickname: "Captain America")
let captain = hero.map { hero -> Hero in
var h = hero
h.nickname = "First Avenger"
return h
}
DD DD
extension Hero {
func get<Value>(_ kp: KeyPath<Hero, Value>) -> Value {
return self[keyPath: kp]
}
func set<Value>(_ kp: WritableKeyPath<Hero, Value>,
_ v: Value) -> Hero {
var h = self
h[keyPath: kp] = v
return h
}
}
let hero = Hero(name: "Steve Rogers",
nickname: "Captain America")
hero.get(.nickname)
//Captain America
let captain = hero.set(.nickname, "First Avenger")
C
struct Lens<Whole, Part> {
let get: (Whole) -> Part
let set: (Whole, Part) -> Whole
}
let heroNickNameLens: Lens<Hero, String> = Lens(
get: { $0.nickname },
set: {
var h = $0
h.nickname = $1
return h
}
)
let hero = Hero(name: "Steve Rogers",
nickname: "Captain America")
let captain = heroNickNameLens.set(hero, "First Avenger")
C
protocol Lensable {
static func lens<Part>(_ wkp: WritableKeyPath<Self, Part>) -> Lens<Self, Part>
}
extension Lensable {
static func lens<Part>(_ wkp: WritableKeyPath<Self, Part>) -> Lens<Self, Part> {
return Lens(
get: { whole in whole[keyPath: wkp] },
set: { whole, part in
var mutableWhole = whole
mutableWhole[keyPath: wkp] = part
return mutableWhole
}
)
}
}
extension Hero: Lensable {}
let hero = Hero(name: "Steve Rogers",
nickname: "Captain America")
let captain = Hero.lens(.nickname).set(hero, "First Avenger")
E D AD C
http://www.cs.ox.ac.uk/people/jeremy.gibbons/publications/poptics.pdf
https://github.com/hablapps/DontFearTheProfunctorOptics
feature
Data
E D
func valueChanger<T, U>(value: T, _ f: (T) -> U) -> U {
return f(value)
}
let name = "Original"
// Original
let changedName = valueChanger(value: name) { "($0) Changed" }
// Original Changed
E D
class Functor<T> {
let value: T
init(_ v: T) {
value = v
}
func map<U>(_ f: (T) -> U) -> Functor<U> {
let u = f(value)
return Functor<U>(u)
}
}
E D
let name = "Original" // Original
let changedName = Functor(name).map { "($0) Changed" }.value
// Original Changed
let changedNameLength = Functor(name) // Functor<String>
.map { "($0) Changed" } // Functor<String>
.map { $0.count } // Functor<Int>
.map { $0 * $0 } // Functor<Int>
.value // Int
// 256
E D
func stringLength(_ s: String) -> Functor<Int> {
return Functor(s).map { $0.count }
}
let name = "Original" // Original
let changedName = Functor(name).map { "($0) Changed" }.value
// Original Changed
let changedNameLength = Functor(name) // Functor<String>
.map { "($0) Changed" } // Functor<String>
.map (stringLength) // Functor<Functor<Int>>
.map { $0 * $0 }
.value
E D
func stringLength(_ s: String) -> Functor<Int> {
return Functor(s).map { $0.count }
}
let name = "Original" // Original
let changedName = Functor(name).map { "($0) Changed" }.value
// Original Changed
let changedNameLength = Functor(name) // Functor<String>
.map { "($0) Changed" } // Functor<String>
.map (stringLength) // Functor<Functor<Int>>
.map { $0 * $0 }
.value
Functor<Functor<Int>> 의 중첩된 것을 단일(Mono)하게 만들어야 함.
class Monad<T>: Functor<T> {
override func map<U>(_ f: (T) -> U) -> Monad<U> {
let cu = super.map(f)
return Monad<U>(cu.value)
}
func flatMap<U>(_ f: (T) -> Functor<U>) -> Monad<U> {
let fu = f(value)
return Monad<U>(fu.value)
}
}
func stringLength(_ s: String) -> Functor<Int> {
return Functor(s).map { $0.count }
}
let name = "Original" // Original
let changedName = Monad(name).map { "($0) Changed" }.value
// Original Changed
let changedNameLength = Monad(name) // Monad<String>
.map { "($0) Changed" } // Monad<String>
.flatMap (stringLength) // Monad<Int>
.map { $0 * $0 } // Monad<Int>
.value // Int
//256
E I
Immutable data 는 변하지 않는 값
f
g = f - ) -
b df - )
-) ).-
e f P
map / flatMap
Data
get / set
유지보수하기 좋다
20190330 immutable data

More Related Content

What's hot

Pooya Khaloo Presentation on IWMC 2015
Pooya Khaloo Presentation on IWMC 2015Pooya Khaloo Presentation on IWMC 2015
Pooya Khaloo Presentation on IWMC 2015
Iran Entrepreneurship Association
 
Climbing the Abstract Syntax Tree (PHP UK 2018)
Climbing the Abstract Syntax Tree (PHP UK 2018)Climbing the Abstract Syntax Tree (PHP UK 2018)
Climbing the Abstract Syntax Tree (PHP UK 2018)
James Titcumb
 
Climbing the Abstract Syntax Tree (Midwest PHP 2020)
Climbing the Abstract Syntax Tree (Midwest PHP 2020)Climbing the Abstract Syntax Tree (Midwest PHP 2020)
Climbing the Abstract Syntax Tree (Midwest PHP 2020)
James Titcumb
 
Climbing the Abstract Syntax Tree (PHP Russia 2019)
Climbing the Abstract Syntax Tree (PHP Russia 2019)Climbing the Abstract Syntax Tree (PHP Russia 2019)
Climbing the Abstract Syntax Tree (PHP Russia 2019)
James Titcumb
 
Class 4 - PHP Arrays
Class 4 - PHP ArraysClass 4 - PHP Arrays
Class 4 - PHP Arrays
Ahmed Swilam
 
Climbing the Abstract Syntax Tree (IPC Fall 2017)
Climbing the Abstract Syntax Tree (IPC Fall 2017)Climbing the Abstract Syntax Tree (IPC Fall 2017)
Climbing the Abstract Syntax Tree (IPC Fall 2017)
James Titcumb
 
Climbing the Abstract Syntax Tree (CodeiD PHP Odessa 2017)
Climbing the Abstract Syntax Tree (CodeiD PHP Odessa 2017)Climbing the Abstract Syntax Tree (CodeiD PHP Odessa 2017)
Climbing the Abstract Syntax Tree (CodeiD PHP Odessa 2017)
James Titcumb
 
Symfony2 - extending the console component
Symfony2 - extending the console componentSymfony2 - extending the console component
Symfony2 - extending the console component
Hugo Hamon
 
Unittests für Dummies
Unittests für DummiesUnittests für Dummies
Unittests für Dummies
Lars Jankowfsky
 
A swift introduction to Swift
A swift introduction to SwiftA swift introduction to Swift
A swift introduction to Swift
Giordano Scalzo
 
Climbing the Abstract Syntax Tree (ScotlandPHP 2018)
Climbing the Abstract Syntax Tree (ScotlandPHP 2018)Climbing the Abstract Syntax Tree (ScotlandPHP 2018)
Climbing the Abstract Syntax Tree (ScotlandPHP 2018)
James Titcumb
 
Swift Programming Language
Swift Programming LanguageSwift Programming Language
Swift Programming Language
Anıl Sözeri
 
Climbing the Abstract Syntax Tree (Southeast PHP 2018)
Climbing the Abstract Syntax Tree (Southeast PHP 2018)Climbing the Abstract Syntax Tree (Southeast PHP 2018)
Climbing the Abstract Syntax Tree (Southeast PHP 2018)
James Titcumb
 
A Few Interesting Things in Apple's Swift Programming Language
A Few Interesting Things in Apple's Swift Programming LanguageA Few Interesting Things in Apple's Swift Programming Language
A Few Interesting Things in Apple's Swift Programming Language
SmartLogic
 
Funkcija, objekt, python
Funkcija, objekt, pythonFunkcija, objekt, python
Funkcija, objekt, python
Robert Lujo
 
Climbing the Abstract Syntax Tree (DPC 2017)
Climbing the Abstract Syntax Tree (DPC 2017)Climbing the Abstract Syntax Tree (DPC 2017)
Climbing the Abstract Syntax Tree (DPC 2017)
James Titcumb
 
Climbing the Abstract Syntax Tree (phpDay 2017)
Climbing the Abstract Syntax Tree (phpDay 2017)Climbing the Abstract Syntax Tree (phpDay 2017)
Climbing the Abstract Syntax Tree (phpDay 2017)
James Titcumb
 
Talk - Query monad
Talk - Query monad Talk - Query monad
Talk - Query monad
Fabernovel
 
Climbing the Abstract Syntax Tree (PHP Developer Days Dresden 2018)
Climbing the Abstract Syntax Tree (PHP Developer Days Dresden 2018)Climbing the Abstract Syntax Tree (PHP Developer Days Dresden 2018)
Climbing the Abstract Syntax Tree (PHP Developer Days Dresden 2018)
James Titcumb
 

What's hot (20)

Pooya Khaloo Presentation on IWMC 2015
Pooya Khaloo Presentation on IWMC 2015Pooya Khaloo Presentation on IWMC 2015
Pooya Khaloo Presentation on IWMC 2015
 
Climbing the Abstract Syntax Tree (PHP UK 2018)
Climbing the Abstract Syntax Tree (PHP UK 2018)Climbing the Abstract Syntax Tree (PHP UK 2018)
Climbing the Abstract Syntax Tree (PHP UK 2018)
 
Php & my sql
Php & my sqlPhp & my sql
Php & my sql
 
Climbing the Abstract Syntax Tree (Midwest PHP 2020)
Climbing the Abstract Syntax Tree (Midwest PHP 2020)Climbing the Abstract Syntax Tree (Midwest PHP 2020)
Climbing the Abstract Syntax Tree (Midwest PHP 2020)
 
Climbing the Abstract Syntax Tree (PHP Russia 2019)
Climbing the Abstract Syntax Tree (PHP Russia 2019)Climbing the Abstract Syntax Tree (PHP Russia 2019)
Climbing the Abstract Syntax Tree (PHP Russia 2019)
 
Class 4 - PHP Arrays
Class 4 - PHP ArraysClass 4 - PHP Arrays
Class 4 - PHP Arrays
 
Climbing the Abstract Syntax Tree (IPC Fall 2017)
Climbing the Abstract Syntax Tree (IPC Fall 2017)Climbing the Abstract Syntax Tree (IPC Fall 2017)
Climbing the Abstract Syntax Tree (IPC Fall 2017)
 
Climbing the Abstract Syntax Tree (CodeiD PHP Odessa 2017)
Climbing the Abstract Syntax Tree (CodeiD PHP Odessa 2017)Climbing the Abstract Syntax Tree (CodeiD PHP Odessa 2017)
Climbing the Abstract Syntax Tree (CodeiD PHP Odessa 2017)
 
Symfony2 - extending the console component
Symfony2 - extending the console componentSymfony2 - extending the console component
Symfony2 - extending the console component
 
Unittests für Dummies
Unittests für DummiesUnittests für Dummies
Unittests für Dummies
 
A swift introduction to Swift
A swift introduction to SwiftA swift introduction to Swift
A swift introduction to Swift
 
Climbing the Abstract Syntax Tree (ScotlandPHP 2018)
Climbing the Abstract Syntax Tree (ScotlandPHP 2018)Climbing the Abstract Syntax Tree (ScotlandPHP 2018)
Climbing the Abstract Syntax Tree (ScotlandPHP 2018)
 
Swift Programming Language
Swift Programming LanguageSwift Programming Language
Swift Programming Language
 
Climbing the Abstract Syntax Tree (Southeast PHP 2018)
Climbing the Abstract Syntax Tree (Southeast PHP 2018)Climbing the Abstract Syntax Tree (Southeast PHP 2018)
Climbing the Abstract Syntax Tree (Southeast PHP 2018)
 
A Few Interesting Things in Apple's Swift Programming Language
A Few Interesting Things in Apple's Swift Programming LanguageA Few Interesting Things in Apple's Swift Programming Language
A Few Interesting Things in Apple's Swift Programming Language
 
Funkcija, objekt, python
Funkcija, objekt, pythonFunkcija, objekt, python
Funkcija, objekt, python
 
Climbing the Abstract Syntax Tree (DPC 2017)
Climbing the Abstract Syntax Tree (DPC 2017)Climbing the Abstract Syntax Tree (DPC 2017)
Climbing the Abstract Syntax Tree (DPC 2017)
 
Climbing the Abstract Syntax Tree (phpDay 2017)
Climbing the Abstract Syntax Tree (phpDay 2017)Climbing the Abstract Syntax Tree (phpDay 2017)
Climbing the Abstract Syntax Tree (phpDay 2017)
 
Talk - Query monad
Talk - Query monad Talk - Query monad
Talk - Query monad
 
Climbing the Abstract Syntax Tree (PHP Developer Days Dresden 2018)
Climbing the Abstract Syntax Tree (PHP Developer Days Dresden 2018)Climbing the Abstract Syntax Tree (PHP Developer Days Dresden 2018)
Climbing the Abstract Syntax Tree (PHP Developer Days Dresden 2018)
 

Similar to 20190330 immutable data

JavaScript for PHP developers
JavaScript for PHP developersJavaScript for PHP developers
JavaScript for PHP developers
Stoyan Stefanov
 
Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02Seri Moth
 
Generics and Inference
Generics and InferenceGenerics and Inference
Generics and Inference
Richard Fox
 
DataTypes.ppt
DataTypes.pptDataTypes.ppt
DataTypes.ppt
RithikRaj25
 
Introduction to Swift programming language.
Introduction to Swift programming language.Introduction to Swift programming language.
Introduction to Swift programming language.
Icalia Labs
 
I keep on get a redefinition error and an undefined error.Customer.pdf
I keep on get a redefinition error and an undefined error.Customer.pdfI keep on get a redefinition error and an undefined error.Customer.pdf
I keep on get a redefinition error and an undefined error.Customer.pdf
herminaherman
 
Functional Programming in PHP
Functional Programming in PHPFunctional Programming in PHP
Functional Programming in PHP
pwmosquito
 
Taking Perl to Eleven with Higher-Order Functions
Taking Perl to Eleven with Higher-Order FunctionsTaking Perl to Eleven with Higher-Order Functions
Taking Perl to Eleven with Higher-Order Functions
David Golden
 
Functional Programming with Groovy
Functional Programming with GroovyFunctional Programming with Groovy
Functional Programming with Groovy
Arturo Herrero
 
Academy PRO: ES2015
Academy PRO: ES2015Academy PRO: ES2015
Academy PRO: ES2015
Binary Studio
 
Swift - 혼자 공부하면 분명히 안할테니까 같이 공부하기
Swift - 혼자 공부하면 분명히 안할테니까 같이 공부하기Swift - 혼자 공부하면 분명히 안할테니까 같이 공부하기
Swift - 혼자 공부하면 분명히 안할테니까 같이 공부하기
Suyeol Jeon
 
Swift 3.0 の新しい機能(のうちの9つ)
Swift 3.0 の新しい機能(のうちの9つ)Swift 3.0 の新しい機能(のうちの9つ)
Swift 3.0 の新しい機能(のうちの9つ)
Tomohiro Kumagai
 
Swift 함수 커링 사용하기
Swift 함수 커링 사용하기Swift 함수 커링 사용하기
Swift 함수 커링 사용하기
진성 오
 
Php functions
Php functionsPhp functions
Php functions
JIGAR MAKHIJA
 
Smelling your code
Smelling your codeSmelling your code
Smelling your code
Raju Mazumder
 
SDC - Einführung in Scala
SDC - Einführung in ScalaSDC - Einführung in Scala
SDC - Einführung in Scala
Christian Baranowski
 
PHP Tips & Tricks
PHP Tips & TricksPHP Tips & Tricks
PHP Tips & Tricks
Radek Benkel
 
Introduction to ECMAScript 2015
Introduction to ECMAScript 2015Introduction to ECMAScript 2015
Introduction to ECMAScript 2015
Tomasz Dziuda
 

Similar to 20190330 immutable data (20)

JavaScript for PHP developers
JavaScript for PHP developersJavaScript for PHP developers
JavaScript for PHP developers
 
Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02
 
Generics and Inference
Generics and InferenceGenerics and Inference
Generics and Inference
 
Scala 2 + 2 > 4
Scala 2 + 2 > 4Scala 2 + 2 > 4
Scala 2 + 2 > 4
 
DataTypes.ppt
DataTypes.pptDataTypes.ppt
DataTypes.ppt
 
Introduction to Swift programming language.
Introduction to Swift programming language.Introduction to Swift programming language.
Introduction to Swift programming language.
 
I keep on get a redefinition error and an undefined error.Customer.pdf
I keep on get a redefinition error and an undefined error.Customer.pdfI keep on get a redefinition error and an undefined error.Customer.pdf
I keep on get a redefinition error and an undefined error.Customer.pdf
 
Functional Programming in PHP
Functional Programming in PHPFunctional Programming in PHP
Functional Programming in PHP
 
Taking Perl to Eleven with Higher-Order Functions
Taking Perl to Eleven with Higher-Order FunctionsTaking Perl to Eleven with Higher-Order Functions
Taking Perl to Eleven with Higher-Order Functions
 
Functional Programming with Groovy
Functional Programming with GroovyFunctional Programming with Groovy
Functional Programming with Groovy
 
Academy PRO: ES2015
Academy PRO: ES2015Academy PRO: ES2015
Academy PRO: ES2015
 
Swift - 혼자 공부하면 분명히 안할테니까 같이 공부하기
Swift - 혼자 공부하면 분명히 안할테니까 같이 공부하기Swift - 혼자 공부하면 분명히 안할테니까 같이 공부하기
Swift - 혼자 공부하면 분명히 안할테니까 같이 공부하기
 
Swift 3.0 の新しい機能(のうちの9つ)
Swift 3.0 の新しい機能(のうちの9つ)Swift 3.0 の新しい機能(のうちの9つ)
Swift 3.0 の新しい機能(のうちの9つ)
 
Swift 함수 커링 사용하기
Swift 함수 커링 사용하기Swift 함수 커링 사용하기
Swift 함수 커링 사용하기
 
Php functions
Php functionsPhp functions
Php functions
 
Smelling your code
Smelling your codeSmelling your code
Smelling your code
 
SDC - Einführung in Scala
SDC - Einführung in ScalaSDC - Einführung in Scala
SDC - Einführung in Scala
 
Wakanday JS201 Best Practices
Wakanday JS201 Best PracticesWakanday JS201 Best Practices
Wakanday JS201 Best Practices
 
PHP Tips & Tricks
PHP Tips & TricksPHP Tips & Tricks
PHP Tips & Tricks
 
Introduction to ECMAScript 2015
Introduction to ECMAScript 2015Introduction to ECMAScript 2015
Introduction to ECMAScript 2015
 

More from Chiwon Song

20240330_고급진 코드를 위한 exception 다루기
20240330_고급진 코드를 위한 exception 다루기20240330_고급진 코드를 위한 exception 다루기
20240330_고급진 코드를 위한 exception 다루기
Chiwon Song
 
요즘 유행하는 AI 나도 해보자 (feat. CoreML)
요즘 유행하는 AI 나도 해보자 (feat. CoreML)요즘 유행하는 AI 나도 해보자 (feat. CoreML)
요즘 유행하는 AI 나도 해보자 (feat. CoreML)
Chiwon Song
 
20220716_만들면서 느껴보는 POP
20220716_만들면서 느껴보는 POP20220716_만들면서 느껴보는 POP
20220716_만들면서 느껴보는 POP
Chiwon Song
 
20210812 컴퓨터는 어떻게 동작하는가?
20210812 컴퓨터는 어떻게 동작하는가?20210812 컴퓨터는 어떻게 동작하는가?
20210812 컴퓨터는 어떻게 동작하는가?
Chiwon Song
 
20201121 코드 삼분지계
20201121 코드 삼분지계20201121 코드 삼분지계
20201121 코드 삼분지계
Chiwon Song
 
20200815 inversions
20200815 inversions20200815 inversions
20200815 inversions
Chiwon Song
 
20191116 custom operators in swift
20191116 custom operators in swift20191116 custom operators in swift
20191116 custom operators in swift
Chiwon Song
 
[20190601] 직업훈련교사_수업의실행_교안
[20190601] 직업훈련교사_수업의실행_교안[20190601] 직업훈련교사_수업의실행_교안
[20190601] 직업훈련교사_수업의실행_교안
Chiwon Song
 
[20190601] 직업훈련교사_수업의실행
[20190601] 직업훈련교사_수업의실행[20190601] 직업훈련교사_수업의실행
[20190601] 직업훈련교사_수업의실행
Chiwon Song
 
20190306 만들면서 배우는 IoT / IoT의 이해
20190306 만들면서 배우는 IoT / IoT의 이해20190306 만들면서 배우는 IoT / IoT의 이해
20190306 만들면서 배우는 IoT / IoT의 이해
Chiwon Song
 
20181020 advanced higher-order function
20181020 advanced higher-order function20181020 advanced higher-order function
20181020 advanced higher-order function
Chiwon Song
 
20180721 code defragment
20180721 code defragment20180721 code defragment
20180721 code defragment
Chiwon Song
 
20180310 functional programming
20180310 functional programming20180310 functional programming
20180310 functional programming
Chiwon Song
 
20171104 FRP 패러다임
20171104 FRP 패러다임20171104 FRP 패러다임
20171104 FRP 패러다임
Chiwon Song
 
스크래치로 시작하는 코딩
스크래치로 시작하는 코딩스크래치로 시작하는 코딩
스크래치로 시작하는 코딩
Chiwon Song
 
메이커운동과 아두이노
메이커운동과 아두이노메이커운동과 아두이노
메이커운동과 아두이노
Chiwon Song
 
아두이노 RC카 만들기
아두이노 RC카 만들기아두이노 RC카 만들기
아두이노 RC카 만들기
Chiwon Song
 
[5] 아두이노로 만드는 IoT
[5] 아두이노로 만드는 IoT[5] 아두이노로 만드는 IoT
[5] 아두이노로 만드는 IoT
Chiwon Song
 
[4] 아두이노와 인터넷
[4] 아두이노와 인터넷[4] 아두이노와 인터넷
[4] 아두이노와 인터넷
Chiwon Song
 
[2] 아두이노 활용 실습
[2] 아두이노 활용 실습[2] 아두이노 활용 실습
[2] 아두이노 활용 실습
Chiwon Song
 

More from Chiwon Song (20)

20240330_고급진 코드를 위한 exception 다루기
20240330_고급진 코드를 위한 exception 다루기20240330_고급진 코드를 위한 exception 다루기
20240330_고급진 코드를 위한 exception 다루기
 
요즘 유행하는 AI 나도 해보자 (feat. CoreML)
요즘 유행하는 AI 나도 해보자 (feat. CoreML)요즘 유행하는 AI 나도 해보자 (feat. CoreML)
요즘 유행하는 AI 나도 해보자 (feat. CoreML)
 
20220716_만들면서 느껴보는 POP
20220716_만들면서 느껴보는 POP20220716_만들면서 느껴보는 POP
20220716_만들면서 느껴보는 POP
 
20210812 컴퓨터는 어떻게 동작하는가?
20210812 컴퓨터는 어떻게 동작하는가?20210812 컴퓨터는 어떻게 동작하는가?
20210812 컴퓨터는 어떻게 동작하는가?
 
20201121 코드 삼분지계
20201121 코드 삼분지계20201121 코드 삼분지계
20201121 코드 삼분지계
 
20200815 inversions
20200815 inversions20200815 inversions
20200815 inversions
 
20191116 custom operators in swift
20191116 custom operators in swift20191116 custom operators in swift
20191116 custom operators in swift
 
[20190601] 직업훈련교사_수업의실행_교안
[20190601] 직업훈련교사_수업의실행_교안[20190601] 직업훈련교사_수업의실행_교안
[20190601] 직업훈련교사_수업의실행_교안
 
[20190601] 직업훈련교사_수업의실행
[20190601] 직업훈련교사_수업의실행[20190601] 직업훈련교사_수업의실행
[20190601] 직업훈련교사_수업의실행
 
20190306 만들면서 배우는 IoT / IoT의 이해
20190306 만들면서 배우는 IoT / IoT의 이해20190306 만들면서 배우는 IoT / IoT의 이해
20190306 만들면서 배우는 IoT / IoT의 이해
 
20181020 advanced higher-order function
20181020 advanced higher-order function20181020 advanced higher-order function
20181020 advanced higher-order function
 
20180721 code defragment
20180721 code defragment20180721 code defragment
20180721 code defragment
 
20180310 functional programming
20180310 functional programming20180310 functional programming
20180310 functional programming
 
20171104 FRP 패러다임
20171104 FRP 패러다임20171104 FRP 패러다임
20171104 FRP 패러다임
 
스크래치로 시작하는 코딩
스크래치로 시작하는 코딩스크래치로 시작하는 코딩
스크래치로 시작하는 코딩
 
메이커운동과 아두이노
메이커운동과 아두이노메이커운동과 아두이노
메이커운동과 아두이노
 
아두이노 RC카 만들기
아두이노 RC카 만들기아두이노 RC카 만들기
아두이노 RC카 만들기
 
[5] 아두이노로 만드는 IoT
[5] 아두이노로 만드는 IoT[5] 아두이노로 만드는 IoT
[5] 아두이노로 만드는 IoT
 
[4] 아두이노와 인터넷
[4] 아두이노와 인터넷[4] 아두이노와 인터넷
[4] 아두이노와 인터넷
 
[2] 아두이노 활용 실습
[2] 아두이노 활용 실습[2] 아두이노 활용 실습
[2] 아두이노 활용 실습
 

Recently uploaded

FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
Fwdays
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 

Recently uploaded (20)

FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 

20190330 immutable data

  • 1. Ra c ) / ED D (-) / ) -
  • 2. G I ED D
  • 3. E var number = 100 mysteryJob() print(number) let number = 100 mysteryJob() print(number)
  • 4. D DI var number = 100 mysteryJob() print(number) // ? let number = 100 mysteryJob() print(number) // 100 mutable immutable
  • 5. F var condition: Bool = true if condition { // true } else { // false } let condition: Bool = true // case true mutable immutable
  • 6. F var condition: Bool = true var condition2: Bool = false if condition { if condition2 { // true && true } else { // true && false } } else { if condition2 { // false && true } else { // false && false } } let condition: Bool = true let condition2: Bool = false // case true && false mutable immutable
  • 7. F var condition: Bool = true var condition2: Bool = false var condition3: Bool = false if condition { if condition2 { if condition3 { // true && true && true } else { // true && true && false } } else { if condition3 { // true && false && true } else { // true && false && false } } } else { if condition2 { if condition3 { // false && true && true } else { // false && true && false } } else { if condition3 { // false && false && true } else { // false && false && false } } } let condition: Bool = true let condition2: Bool = false let condition2: Bool = false // case true && false && false mutable immutable
  • 8. / D Data Program Program Program Program Data Program Program Program Program mutable immutable
  • 9. D C mutable immutable struct Hero { var name : String var nickname: String } var hero = Hero(name: "Steve Rogers", nickname: "Captain America") print(hero) //Hero(name: "Steve Rogers", nickname: "Captain America") hero.nickname = "First Avenger" print(hero) //Hero(name: "Steve Rogers", nickname: "First Avengers") struct Hero { var name : String var nickname: String } let hero = Hero(name: "Steve Rogers", nickname: "Captain America") print(hero) //Hero(name: "Steve Rogers", nickname: "Captain America") let captain = Hero(name: hero.name, nickname: "First Avenger") print(hero) //Hero(name: "Steve Rogers", nickname: "Captain America") print(captain) //Hero(name: "Steve Rogers", nickname: "First Avengers")
  • 10. ED D 1. Predictable 2. Testability 3. Thread-Safe Maintainable } 4. Unfamiliar 5. Memory wasting 6. Low performance ( in some case )
  • 11. ED FC ED D Maintenance Performance vs
  • 14. AI struct Hero { var name: String var nickname: String } let hero = Hero(name: "Steve Rogers", nickname: "Captain America") var captain = hero captain.nickname = "First Avenger" Copy On Write
  • 15. HD C protocol Mappable { func map<U>(_ f: (Self) -> U) -> U } extension Mappable { func map<U>(_ f: (Self) -> U) -> U { return f(self) } } extension Hero: Mappable { } let hero = Hero(name: "Steve Rogers", nickname: "Captain America") let captain = hero.map { hero -> Hero in var h = hero h.nickname = "First Avenger" return h }
  • 16. DD DD extension Hero { func get<Value>(_ kp: KeyPath<Hero, Value>) -> Value { return self[keyPath: kp] } func set<Value>(_ kp: WritableKeyPath<Hero, Value>, _ v: Value) -> Hero { var h = self h[keyPath: kp] = v return h } } let hero = Hero(name: "Steve Rogers", nickname: "Captain America") hero.get(.nickname) //Captain America let captain = hero.set(.nickname, "First Avenger")
  • 17. C struct Lens<Whole, Part> { let get: (Whole) -> Part let set: (Whole, Part) -> Whole } let heroNickNameLens: Lens<Hero, String> = Lens( get: { $0.nickname }, set: { var h = $0 h.nickname = $1 return h } ) let hero = Hero(name: "Steve Rogers", nickname: "Captain America") let captain = heroNickNameLens.set(hero, "First Avenger")
  • 18. C protocol Lensable { static func lens<Part>(_ wkp: WritableKeyPath<Self, Part>) -> Lens<Self, Part> } extension Lensable { static func lens<Part>(_ wkp: WritableKeyPath<Self, Part>) -> Lens<Self, Part> { return Lens( get: { whole in whole[keyPath: wkp] }, set: { whole, part in var mutableWhole = whole mutableWhole[keyPath: wkp] = part return mutableWhole } ) } } extension Hero: Lensable {} let hero = Hero(name: "Steve Rogers", nickname: "Captain America") let captain = Hero.lens(.nickname).set(hero, "First Avenger")
  • 19. E D AD C http://www.cs.ox.ac.uk/people/jeremy.gibbons/publications/poptics.pdf https://github.com/hablapps/DontFearTheProfunctorOptics
  • 21. E D func valueChanger<T, U>(value: T, _ f: (T) -> U) -> U { return f(value) } let name = "Original" // Original let changedName = valueChanger(value: name) { "($0) Changed" } // Original Changed
  • 22. E D class Functor<T> { let value: T init(_ v: T) { value = v } func map<U>(_ f: (T) -> U) -> Functor<U> { let u = f(value) return Functor<U>(u) } }
  • 23. E D let name = "Original" // Original let changedName = Functor(name).map { "($0) Changed" }.value // Original Changed let changedNameLength = Functor(name) // Functor<String> .map { "($0) Changed" } // Functor<String> .map { $0.count } // Functor<Int> .map { $0 * $0 } // Functor<Int> .value // Int // 256
  • 24. E D func stringLength(_ s: String) -> Functor<Int> { return Functor(s).map { $0.count } } let name = "Original" // Original let changedName = Functor(name).map { "($0) Changed" }.value // Original Changed let changedNameLength = Functor(name) // Functor<String> .map { "($0) Changed" } // Functor<String> .map (stringLength) // Functor<Functor<Int>> .map { $0 * $0 } .value
  • 25. E D func stringLength(_ s: String) -> Functor<Int> { return Functor(s).map { $0.count } } let name = "Original" // Original let changedName = Functor(name).map { "($0) Changed" }.value // Original Changed let changedNameLength = Functor(name) // Functor<String> .map { "($0) Changed" } // Functor<String> .map (stringLength) // Functor<Functor<Int>> .map { $0 * $0 } .value Functor<Functor<Int>> 의 중첩된 것을 단일(Mono)하게 만들어야 함.
  • 26. class Monad<T>: Functor<T> { override func map<U>(_ f: (T) -> U) -> Monad<U> { let cu = super.map(f) return Monad<U>(cu.value) } func flatMap<U>(_ f: (T) -> Functor<U>) -> Monad<U> { let fu = f(value) return Monad<U>(fu.value) } }
  • 27. func stringLength(_ s: String) -> Functor<Int> { return Functor(s).map { $0.count } } let name = "Original" // Original let changedName = Monad(name).map { "($0) Changed" }.value // Original Changed let changedNameLength = Monad(name) // Monad<String> .map { "($0) Changed" } // Monad<String> .flatMap (stringLength) // Monad<Int> .map { $0 * $0 } // Monad<Int> .value // Int //256
  • 28. E I Immutable data 는 변하지 않는 값 f g = f - ) - b df - ) -) ).- e f P map / flatMap Data get / set 유지보수하기 좋다