Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
ClojureScript のある生活
Search
ayato
December 16, 2015
Programming
3
2.9k
ClojureScript のある生活
ayato
December 16, 2015
Tweet
Share
More Decks by ayato
See All by ayato
Clojureという言語が私逹にもたらしたもの
ayato0211
6
2.9k
3年間考え続けてきたWebアプリケーションにおけるテストの話
ayato0211
3
230
Re:REPL-Driven Development
ayato0211
3
1.2k
Meta Template Engine
ayato0211
2
1k
超変換! Hiccup data structure!!
ayato0211
2
550
About Integrant
ayato0211
0
490
Muscle Assert
ayato0211
0
210
Clojureを用いたWebアプリケーション開発
ayato0211
2
3k
翻訳にまつわるエトセトラ
ayato0211
6
1.2k
Other Decks in Programming
See All in Programming
watsonx.ai Dojo #4 生成AIを使ったアプリ開発、応用編
oniak3ibm
PRO
1
150
イベント駆動で成長して委員会
happymana
1
340
Flutterを言い訳にしない!アプリの使い心地改善テクニック5選🔥
kno3a87
1
200
初めてDefinitelyTypedにPRを出した話
syumai
0
420
とにかくAWS GameDay!AWSは世界の共通言語! / Anyway, AWS GameDay! AWS is the world's lingua franca!
seike460
PRO
1
900
EMになってからチームの成果を最大化するために取り組んだこと/ Maximize team performance as EM
nashiusagi
0
100
CSC509 Lecture 09
javiergs
PRO
0
140
Make Impossible States Impossibleを 意識してReactのPropsを設計しよう
ikumatadokoro
0
240
CSC509 Lecture 12
javiergs
PRO
0
160
タクシーアプリ『GO』のリアルタイムデータ分析基盤における機械学習サービスの活用
mot_techtalk
4
1.5k
as(型アサーション)を書く前にできること
marokanatani
10
2.7k
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
1
100
Featured
See All Featured
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
329
21k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
27
4.3k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
47
2.1k
Building Your Own Lightsaber
phodgson
103
6.1k
What's new in Ruby 2.0
geeforr
343
31k
Testing 201, or: Great Expectations
jmmastey
38
7.1k
Keith and Marios Guide to Fast Websites
keithpitt
409
22k
Git: the NoSQL Database
bkeepers
PRO
427
64k
Thoughts on Productivity
jonyablonski
67
4.3k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
44
2.2k
Embracing the Ebb and Flow
colly
84
4.5k
Raft: Consensus for Rubyists
vanstee
136
6.6k
Transcript
$MPKVSF4DSJQU ͕ ͋Δੜ׆ !@BZBUP@Q
ࣗݾհ +4Φδαϯ$MPKVSFΦδαϯ +BWB4DSJQUॳ৺ऀͰ͢ ࠓ$MPKVSF͔͠ॻ͍ͯͳ͍ਓ $ZCP[V4UBSUVQT *OD
͜Μͳܦݧ͋Γ·ͤΜ͔ʁ ྫ͑ΦϯϥΠϯγϣοϓΈ͍ͨͳγεςϜɻ
͜Μͳܦݧ͋Γ·ͤΜ͔ʁ Χʔτͷ߹ܭֹۚΛϑϩϯτΤϯυͱ αʔόʔαΠυ྆ํͰಉ͡ܭࢉΛ͢Δඞཁ͕͋Δɻ
͜Μͳܦݧ͋Γ·ͤΜ͔ʁ ͔͠͠ɺֹۚܭࢉͳͷͰͲͪΒʹ ಉ࣮͢͡Δͱ͍͏͜ͱͨ͘͠ͳ͍ɻ
͜Μͳܦݧ͋Γ·ͤΜ͔ʁ ߹ܭֹۚܭࢉ"1*Λୟ͖·ͬͯ͘ αʔόʔαΠυͰܭࢉͨ݁͠ՌΛϑϩϯτʹฦ͢
͜Μͳܦݧ͋Γ·ͤΜ͔ʁ ී௨ʹߟ͑ͯͭΒ͍ ඇಉظॲཧΛྻԽͨ͠ΓɺϝϞԽͨ͠Γେม
ͦ͜Ͱ$MPKVSF4DSJQUͰ͢Α 3FBEFS$POEJUJPOBMTͷ͓ӄͰ 8SJUFPODF SVOBOZXIFSF 5SBOTJUϑΥʔϚοτͰ γʔϜϨεͳσʔλ௨৴ ϑϩϯτΤϯυαʔόʔαΠυ $MPKVSFͷ͚ࣝͩͰॻ͚Δ
$MPKVSF4DSJQU "MU+4ͱ͍͏ΑΓ$MPKVSFͷλʔήοτ͕ +7.Ͱͳ͘+BWB4DSJQUʹͳͬͨͷ ΄ͱΜͲ$MPKVSFͱಉ͚ͩ͡ͲɺҰ෦ҧ͏ JOUFSPQͱ͔ϚΫϩ͑Δ͚Ͳॻ͚ͳ͍ͱ͔ ΤίγεςϜ͕ڧ͍ ͱͯ 'JHXIFFMͰ8FC1BDL).3ͱಉ
#SPXTFS3&1-ͰϒϥβڥऔΕΔ
3FBEFS$POEJUJPOBMT $MPKVSF͔Β͑ΔΑ͏ʹͳͬͨݴޠػೳ DMKD֦ுࢠͰఆ͓ٛͯ͘͠ͱ $MPKVSF$MPKVSF4DSJQUͲͪΒ͔ΒಡࠐՄೳ ݴޠಛ༗ͷ͚ͩΛࠩఆٛग़དྷΔ
;; dates (.getTime #?(:clj (java.util.Date.) :cljs (js/Date.))) ;; uris #?(
:clj (defn url-encode [string] (some-> string str (URLEncoder/encode "UTF-8") (.replace "+" "%20"))) :cljs (defn url-encode [string] (some-> string str (js/encodeURIComponent) (.replace "+" "%20")))) ;; reflection warnings #?(:clj (set! *warn-on-reflection* true)) 3FBEFS$POEJUJPOBMT
5SBOTJU $MPKVSFͰ༗໊ͳ$PHOJUFDUͷ࡞ͬͨ ৽͍͠σʔλϑΥʔϚοτ ϓϩάϥϜಉ࢜ͷίϛϡχέʔγϣϯʹ͑Δ ϢʔβʔఆٛܕใΛૹड৴͢Δ͜ͱ͕ग़དྷΔ ωετͨͨͩ͠ͷϚοϓྻͱάοόΠ
(ns transit-demo.core (:require [cognitect.transit :as transit]) (:import [java.io ByteArrayInputStream ByteArrayOutputStream]))
(def custom-writer (transit/write-handler-map {Cart (transit/write-handler (constantly "cart") #(:items %)) Item (transit/write-handler (constantly "item") #(apply vector (vals %)))})) (def out (ByteArrayOutputStream. 4096)) (def writer (transit/writer out :json {:handlers custom-writer})) 5SBOTJU
(defprotocol Calculatable (calculate [x])) (defrecord Cart [items] Calculatable (calculate [self]
(apply + (map calculate items)))) (defn new-cart [items] (map->Cart {:items items})) (defrecord Item [name price] Calculatable (calculate [self] (* price 1.08))) (defn new-item [name price] (map->Item {:name name, :price price})) 5SBOTJU
(def my-cart-data (new-cart [(new-item "Clojure Programming" 1000) (new-item "Clojure Applied"
2500)])) (transit/write writer my-cart-data) (.toString out) ;; => "[\"~#cart\",[[\"~#item\",[\"Clojure Programming\",1000]], ;; [\"^1\",[\"Clojure Applied\",2500]]]]" 5SBOTJU
(def custom-reader (transit/read-handler-map {"cart" (transit/read-handler new-cart) "item" (transit/read-handler #(apply new-item
%))})) (def in (ByteArrayInputStream. (.toByteArray out))) (def reader (transit/reader in :json {:handlers custom-reader})) (def my-cart-data' (transit/read reader)) (calculate my-cart-data') ;; => 3780.0 5SBOTJU
ͭ·Γ 5SBOTJU8SJUFS3FBEFS 5ZQF3FDPSE DMK DMKD DMKT 1SPUPDPM 4FSWFSTJEF $MJFOUTJEF
།Ұͷܽ 3BUJPܕ͕$MPKVSF4DSJQUͰαϙʔτ͞Εͳ͍ ϥΠϒϥϦͰղܾͰ͖ΔͷͰͳ͍
·ͱΊ 5SBOTJUϑΥʔϚοτͰγʔϜϨεʹ σʔλΛड͚ͤΔ 3FBEFS$POEJUJPOBMTͰϑϩϯτͱαʔόʔα ΠυͰඞཁͳॲཧΛڞ௨Խग़དྷΔ $MPKVSF࠷ߴʂ
Enjoy Clojure