SlideShare a Scribd company logo
1 of 29
Download to read offline
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

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 ArraysAhmed 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 componentHugo Hamon
 
A swift introduction to Swift
A swift introduction to SwiftA swift introduction to Swift
A swift introduction to SwiftGiordano 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 LanguageAnı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 LanguageSmartLogic
 
Funkcija, objekt, python
Funkcija, objekt, pythonFunkcija, objekt, python
Funkcija, objekt, pythonRobert 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 developersStoyan Stefanov
 
Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02Seri Moth
 
Generics and Inference
Generics and InferenceGenerics and Inference
Generics and InferenceRichard Fox
 
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.pdfherminaherman
 
Functional Programming in PHP
Functional Programming in PHPFunctional Programming in PHP
Functional Programming in PHPpwmosquito
 
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 FunctionsDavid Golden
 
Functional Programming with Groovy
Functional Programming with GroovyFunctional Programming with Groovy
Functional Programming with GroovyArturo Herrero
 
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 함수 커링 사용하기진성 오
 
Introduction to ECMAScript 2015
Introduction to ECMAScript 2015Introduction to ECMAScript 2015
Introduction to ECMAScript 2015Tomasz 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_만들면서 느껴보는 POPChiwon Song
 
20210812 컴퓨터는 어떻게 동작하는가?
20210812 컴퓨터는 어떻게 동작하는가?20210812 컴퓨터는 어떻게 동작하는가?
20210812 컴퓨터는 어떻게 동작하는가?Chiwon Song
 
20201121 코드 삼분지계
20201121 코드 삼분지계20201121 코드 삼분지계
20201121 코드 삼분지계Chiwon Song
 
20200815 inversions
20200815 inversions20200815 inversions
20200815 inversionsChiwon Song
 
20191116 custom operators in swift
20191116 custom operators in swift20191116 custom operators in swift
20191116 custom operators in swiftChiwon 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 functionChiwon Song
 
20180721 code defragment
20180721 code defragment20180721 code defragment
20180721 code defragmentChiwon Song
 
20180310 functional programming
20180310 functional programming20180310 functional programming
20180310 functional programmingChiwon 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] 아두이노로 만드는 IoTChiwon 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

Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 

Recently uploaded (20)

Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 

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 유지보수하기 좋다