This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn lazy-seq* [reducible] | |
(let [c (chan) | |
NIL (Object.) | |
encode-nil #(if (nil? %) NIL %) | |
decode-nil #(if (identical? NIL %) nil %) | |
reduce-fn (fn [r v] (>!! c (encode-nil v)))] | |
(thread | |
(reduce reduce-fn nil reducible) | |
(close! c)) | |
(->> #(<!! c) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns foo.core | |
(:api dunaj) | |
(:require [dunaj.host.int :refer [i== iDOT]] | |
[dunaj.host.array :as dha] | |
[dunaj.format.base64 :refer [base64-safe]] | |
[dunaj.coll.recipe :refer [concat*]] | |
[dunaj.concurrent.port :refer [reduce! onto-chan!]])) | |
(def+ ByteColl [java.lang.Byte]) ;; type signature |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun set-window-width (n) | |
"Set the selected window's width." | |
(adjust-window-trailing-edge (selected-window) (- n (window-width)) t)) | |
(defun set-70-columns () | |
"Set the selected window to 80 columns." | |
(interactive) | |
(set-window-width 70)) | |
(global-set-key "\C-x`" 'set-70-columns) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;;; 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defprotocol IReducing | |
"A value protocol for augmented reducing functions." | |
(-init | |
"Returns default initial unwrapped value." | |
[this]) | |
(-finish | |
"Returns final wrapped result, and performs flushing or cleaning | |
of internal state. Returned wrap should have cleaned state, | |
so that eventual subsequent calls to -finish will perform | |
correctly. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns redtest.core | |
(:require [clojure.core.reducers] | |
[clojure.core.protocols :refer | |
[CollReduce coll-reduce]])) | |
;; state is kept in a ret | |
(deftype WrapState [ret n]) | |
(deftype WrapTake [coll n] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
JSON-LD | |
{ | |
"@context": { | |
"name": "http://xmlns.com/foaf/0.1/name", | |
"homepage": { | |
"@id": "http://xmlns.com/foaf/0.1/homepage", | |
"@type": "@id" | |
} | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
alert(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; excerpt of foldable multireducible impl | |
;; | |
;; - introducing concept of mutable iterator, which is | |
;; much faster than seq | |
;; - this is for a (yet unreleased) custom patched clojure, | |
;; where clojure.lang interfaces can behave like protocols | |
;; - map is reducer variant, thats why I have to call seq on it | |
;; - seq is patched to support any reducible, not just Seqable | |
(defn fold-sectionable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Multireducibles (with support for folding) | |
(def s1 "Hello World") | |
(def s2 "lllllllllll") | |
;; create multireducible with zip | |
(seq (zip s1 s2)) | |
;; => ((\H \l) (\e \l) (\l \l) (\l \l) (\o \l) (\space \l) (\W \l) (\o \l) (\r \l) (\l \l) (\d \l)) |