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
Nurturing OpenJDK distribution: Eclipse Temurin Success History and plan
ivargrimstad
0
900
CSC509 Lecture 12
javiergs
PRO
0
160
Creating a Free Video Ad Network on the Edge
mizoguchicoji
0
120
[Do iOS '24] Ship your app on a Friday...and enjoy your weekend!
polpielladev
0
100
型付き API リクエストを実現するいくつかの手法とその選択 / Typed API Request
euxn23
8
2.2k
Amazon Qを使ってIaCを触ろう!
maruto
0
410
Less waste, more joy, and a lot more green: How Quarkus makes Java better
hollycummins
0
100
macOS でできる リアルタイム動画像処理
biacco42
9
2.4k
CSC509 Lecture 11
javiergs
PRO
0
180
Make Impossible States Impossibleを 意識してReactのPropsを設計しよう
ikumatadokoro
0
170
Pinia Colada が実現するスマートな非同期処理
naokihaba
4
220
Laravel や Symfony で手っ取り早く OpenAPI のドキュメントを作成する
azuki
2
120
Featured
See All Featured
The Pragmatic Product Professional
lauravandoore
31
6.3k
Making Projects Easy
brettharned
115
5.9k
Ruby is Unlike a Banana
tanoku
97
11k
GraphQLとの向き合い方2022年版
quramy
43
13k
Embracing the Ebb and Flow
colly
84
4.5k
Faster Mobile Websites
deanohume
305
30k
Visualization
eitanlees
145
15k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.8k
Facilitating Awesome Meetings
lara
50
6.1k
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.4k
Being A Developer After 40
akosma
86
590k
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