Skip to content

weavejester/substream

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Substream

Build Status

Substream is a small library for constructing subclasses of java.io.InputStream from standard Clojure functions.

This is necessary due to the limitations of subclassing in clojure.

Installation

To install, add the following to your project :dependencies:

[substream "0.1.0"]

Usage

The substream.core/input-stream function will construct a new InputStream instance from a zero-argument Clojure function. The function can returns a value representing a byte from the stream. The return value may be an integer, byte or nil if the stream has ended.

(require '[substream.core :as substream])

(def data
  (ref (seq (.getBytes "Hello World"))))

(def stream
  (substream/input-stream
   #(dosync
      (when (seq @state)
        (let [value (first @state)]
          (alter state next)
          value))))

License

Copyright © 2014 James Reeves

Distributed under the MIT License.

About

Stream subclassing in Clojure

Resources

Stars

Watchers

Forks

Packages

No packages published