$30 off During Our Annual Pro Sale. View Details »
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
NDS_36_RubyCurry
Search
kasacchiful
March 15, 2014
Programming
0
1.4k
NDS_36_RubyCurry
NDS#36 の言語セッションでしゃべった内容です。
kasacchiful
March 15, 2014
Tweet
Share
More Decks by kasacchiful
See All by kasacchiful
dbt coreとFargateでデータ変換 / 20240928-jawsug-toyama-hokuriku-shinkansen
kasacchiful
1
48
What we keep in mind when migrating from Serverless Framework to AWS CDK and AWS SAM
kasacchiful
1
250
AWSでIcebergを使ってデータウェアハウスを構築してみる / 20240810-jawsug-akita
kasacchiful
0
29
サーバーレスパターンを元にAWS CDKでデータ基盤を構築する / 20240731_classmethod_odyssey_online_build_a_data_infrastructures_using_aws_cdk_based_on_serverless_patterns
kasacchiful
0
400
AWS IoT 1-clickがサービス終了するので、SORACOMに移行した話 / 20240518-jawsug-niigata-iotlt-niigata
kasacchiful
0
220
AWS Application Composerで始める、 サーバーレスなデータ基盤構築 / 20240406-jawsug-hokuriku-shinkansen
kasacchiful
1
520
AWSの各種サービス紹介と活用方法 − AI・ML活用デモを交えて − / 20231208aws-aiml-seminar
kasacchiful
0
490
Amazon Rekognition デモ / 20231208-aws_seminar-01-rekognition-demo
kasacchiful
0
510
Amazon Lookout for Vision デモ / 20231208-aws_seminar-02-lookout-vision-demo
kasacchiful
0
500
Other Decks in Programming
See All in Programming
Reckoner における Datadog Browser Test の活用事例 / Datadog Browser Test at Reckoner
nomadblacky
0
180
事業成長を爆速で進めてきたプロダクトエンジニアたちの成功談・失敗談
nealle
3
980
eBPF Deep Dive: Architecture and Safety Mechanisms
takehaya
12
1.1k
romajip: 日本の住所CSVデータを活用した英語住所変換ライブラリを作った話
sangunkang
0
2.2k
watsonx.ai Dojo #4 生成AIを使ったアプリ開発、応用編
oniak3ibm
PRO
1
260
聞き手から登壇者へ: RubyKaigi2024 LTでの初挑戦が 教えてくれた、可能性の星
mikik0
1
140
新規学習のハードルを下げる方法とは?/ How to Make Learning Something New Easier?
nobuoooo
1
130
Arm移行タイムアタック
qnighy
0
390
Contemporary Test Cases
maaretp
0
150
距離関数を極める! / SESSIONS 2024
gam0022
0
340
Thoughts and experiences on Rust and TypeScript
unvalley
2
200
Modular Monolith Monorepo ~シンプルさを保ちながらmonorepoのメリットを最大化する~
yuisakamoto
10
3.7k
Featured
See All Featured
Gamification - CAS2011
davidbonilla
80
5k
Docker and Python
trallard
40
3.1k
Code Reviewing Like a Champion
maltzj
520
39k
The Power of CSS Pseudo Elements
geoffreycrofte
73
5.3k
Building Adaptive Systems
keathley
38
2.3k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.2k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
111
49k
It's Worth the Effort
3n
183
27k
The Language of Interfaces
destraynor
154
24k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
Visualization
eitanlees
145
15k
Fashionably flexible responsive web design (full day workshop)
malarkey
405
65k
Transcript
RubyͷCurryΛ গ͠৯ͯΈͨ ּݪɹʢ@kasacchifulʣ
ࣗݾհ • ּݪɹʢ@kasacchifulʣ • ৽ׁࢢࡏॅ • SIerۈʢΠϯϑϥඋ͕ଟΊʣ • Ruby͕͓ؾʹೖΓ •
VB.NET, Javascript, SQL, PHP, PowerShell
એ
JaSST’14 Niigata • ࣌ɿ20144݄11ʢۚʣ10:00 ʙ 16:50 • ձɿगϝοηɹதձٞࣨ302B • جௐߨԋɿদඌ୩
ప ࢯʮςετͷલʹνʔϜͷݱྗΛσόοά!!ɹɹ ʙݱྗΛܭଌ͠ɼ߹ཧతͳຏ͖ํΛֶͿʙʯ • ϫʔΫγϣοϓɿ૿ా ྱࢠ ࢯʮݱྗͱνʔϜϏϧσΟϯάɹɹɹɹ ʙνʔϜΛ࡞ͬͯɼຏ͍͍ͯͨ͘Ίʹʙʯ • ਃࠐకɿ20144݄4ʢۚʣ • Webɿhttp://jasst.jp/symposium/jasst14niigata.html
Ruby • 19932݄24ੜ·Εɺ1995ެ։ • ΦϒδΣΫτࢦʢ͕ͯ͢ΦϒδΣΫτʣ • ڧ͍ಈతܕ͚ • ެࣜϖʔδɿhttps://www.ruby-lang.org/ja/
Ruby ͷ Curry ͬͯԿʁ
Ruby ͷ Curry hoge = -> (x,y,z) { x +
y * z } ## hoge = lambda {|x,y,z| x + y * z} ͱಉ͡ curry_hoge = hoge.curry ! hoge.call(1,2,3) #=> 7 hoge[2,3,4] #=> 14 ! curry_hoge.call(1).call(2).call(3) #=> 7 curry_hoge[2][3][4] #=> 14
ͦͦ Curry ͬͯԿʁ
Curry ʮΧϦʔԽʯͷ͜ͱ ΧϦʔԽ (currying) ͱɺܭࢉػՊֶͷٕ๏ͷҰͭɻ ෳͷҾΛͱΔؔΛɺҾ͕ʮͱͷؔͷ࠷ॳͷ ҾʯͰΓ͕ʮͱͷؔͷΓͷҾΛऔΓ݁Ռ Λฦؔ͢ʯͰ͋ΔΑ͏ͳؔʹ͢Δ͜ͱɻ ʢग़యɿʮΧϦʔԽ -
Wikipediaʯʣ http://ja.wikipedia.org/wiki/%E3%82%AB%E3%83%AA%E3%83%BC%E5%8C%96
Ruby ͷ Curry hoge = ->(x,y,z) { x + y
* z } curry_hoge = hoge.curry ## curry_hoge = ->(x) { ->(y) { ->(z) { x + y * z }}} ͱಉ͡ ! ɾProc#curry Ruby 1.9 ͔Β͑Δ
Curry ͓͍͍ͬͯ͠ͷʁ
͓͍͍͖ͨͩ͘͠·͠ΐ͏ ΧϦʔԽ͢Δ͜ͱͰɺطଘͷؔʹҾͷΛ෦ద༻͠ ͯɺผͷؔΛ࡞Δ͜ͱ͕ग़དྷ·͢ɻ ! طଘͷؔͷ࠶ར༻ɹɹɹɹɹʮDRYʯɹ ! ͏·͑͘ɺ͓͍͘͠ͳΓ·͢ɻ
Wikipedia ͷྫΛ Ruby Ͱ div = ->(x,y) { x /
y } ## currying cdiv = div.curry #=> ->(x) {->(y) { x/ y }} ## partial application inv = cdiv[1.0] #=> ->(y) { 1.0 / y } inv[3] #=> 0.3333333333333333 inv[10] #=> 0.1
ҙ ʮΧϦʔԽʯͱʮ෦ద༻ʯΛؒҧ͑ͳ͍Α͏ʹ ! ΧϦʔԽɿ->(x,y){x/y} Λ ->(x){->(y){x/y}} ʹม͢Δ͜ͱ ෦ద༻ɿҰ෦ͷҾʹΛద༻ͯ͠ɺผͷؔΛͭ͘Δ ͜ͱ
ଞݴޠͰͷ Curry • ୈҰڃؔΛѻ͑ΔݴޠͰ͋ΕɺΧϦʔԽΛ࣮ࢪ͢Δ ؔΛ࣮Մೳɻ • ྫɿLISP, Scheme, F#, Scala,
Erlang, Eiffel, Perl, Python, Rݴޠ, Sݴޠ, JavaScript • ϥΠϒϥϦͰɺΧϦʔԽؔΛ͑Δݴޠ͋Δ • Groovy ͷ curry ෦ద༻ͳͷͰҙ ग़యɿʮΧϦʔԽ - Wikipediaʯ http://ja.wikipedia.org/wiki/%E3%82%AB%E3%83%AA%E3%83%BC%E5%8C%96
Curry ΛͬͯΈΔ
FizzBuzzͯ͠ΈΔ
·ͱΊ
͓͍͍͠CurryΛ࡞ͬͯ ͓͍͍͖ͨͩ͘͠·͠ΐ͏
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠