Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
;;;; transducer parser
;; channel that parses input bytes into utf8 chars
(def c (chan 10 (parse utf8)))
;;=> #'foo.baz/c
;; vector of utf8 encoded characters
(def v [-16 -99 -109 -105 -16 -99 -109 -82 -16 -99 -109 -75 -16 -99 -109 -75 -16 -99 -109 -72 32 -16 -99 -108 -128 -16 -99 -109 -72 -16 -99 -109 -69 -16 -99 -109 -75 -16 -99 -109 -83])
;;=> #'foo.baz/v
;; feed collection into the channel
(def dc (onto-chan! c v))
;;=> #'foo.baz/dc
;; close channel when feeding is done, so that reduce! finishes
(thread (<!! dc) (close! c))
;;=> #<ManyToManyChannel clojure.core.async.impl.channels.ManyToManyChannel@1c8529e4>
;; reads all from channel and converts to string
(str (<!! (reduce! conj [] c)))
;;=> "𝓗𝓮𝓵𝓵𝓸 𝔀𝓸𝓻𝓵𝓭"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment