Skip to content

Instantly share code, notes, and snippets.

@jgomo3
Created February 15, 2021 22:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jgomo3/b48e78faa192e68212ed6b1497bf1d19 to your computer and use it in GitHub Desktop.
Save jgomo3/b48e78faa192e68212ed6b1497bf1d19 to your computer and use it in GitHub Desktop.
Streaming an edn... failing at the end
(ns playground.stream-edn
(:require [clojure.java.io :as io]
[clojure.edn :as edn])
(:gen-class))
(defn edn-reader [rsrc-name]
(->> rsrc-name
io/resource
io/reader
(#(java.io.PushbackReader. %))))
(defn edn-stream [rsrc-name]
(let [reader (edn-reader rsrc-name)
next-edn #(edn/read reader)]
(repeatedly next-edn)))
(take 2 (edn-stream "example.edn"))
(count (edn-stream "example.edn"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment