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
560
About Integrant
ayato0211
0
500
Muscle Assert
ayato0211
0
220
Clojureを用いたWebアプリケーション開発
ayato0211
2
3k
翻訳にまつわるエトセトラ
ayato0211
6
1.2k
Other Decks in Programming
See All in Programming
たのしいparse.y
ydah
3
120
採用事例の少ないSvelteを選んだ理由と それを正解にするためにやっていること
oekazuma
2
1k
talk-with-local-llm-with-web-streams-api
kbaba1001
0
180
命名をリントする
chiroruxx
1
400
アクターシステムに頼らずEvent Sourcingする方法について
j5ik2o
4
260
暇に任せてProxmoxコンソール 作ってみました
karugamo
2
720
テスト自動化失敗から再挑戦しチームにオーナーシップを委譲した話/STAC2024 macho
ma_cho29
1
1.3k
「とりあえず動く」コードはよい、「読みやすい」コードはもっとよい / Code that 'just works' is good, but code that is 'readable' is even better.
mkmk884
3
230
今年のアップデートで振り返るCDKセキュリティのシフトレフト/2024-cdk-security-shift-left
tomoki10
0
200
tidymodelsによるtidyな生存時間解析 / Japan.R2024
dropout009
1
770
Jakarta EE meets AI
ivargrimstad
0
240
Symfony Mapper Component
soyuka
2
730
Featured
See All Featured
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
28
2.1k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
2
290
How To Stay Up To Date on Web Technology
chriscoyier
789
250k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.7k
A Modern Web Designer's Workflow
chriscoyier
693
190k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
Being A Developer After 40
akosma
87
590k
Documentation Writing (for coders)
carmenintech
66
4.5k
Code Reviewing Like a Champion
maltzj
520
39k
BBQ
matthewcrist
85
9.4k
Optimizing for Happiness
mojombo
376
70k
Scaling GitHub
holman
458
140k
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