Fork me on GitHub

I very seldom use proxy so I’m probably doing something wrong that’s elementary. I’m trying to proxy OutputStream and implement the write(byte b) method. Unfortunately, it’s not working:


(.write rwos (byte 1))
IllegalArgumentException No matching method found: write for class bleach.outputstream.proxy$$ff19274a  clojure.lang.Reflector.invokeMatchingMethod (


It seems as if the write fn is only accepting the byte[] argument. If I add a ^byte type hint, the compiler yells at me:

CompilerException java.lang.IllegalArgumentException: Only long and double primitives are supported


@bj At that sort of level I’d probably look at :pre / :post assertions on the function itself — although I would only bother with such validation at subsystem boundaries rather than on every function. If you want that sort of protection, you probably want a statically typed language instead of Clojure...


@bj And bear in mind that map can be applied to things that, for example, coll? will return false on so you’ll have to be pretty careful about which predicates you use for such validation.


(the convenient one here I think is seqable? but that’s new in Clojure 1.9.0)


@bj you can use plumatic/schema, but anything more than simple validation is a bit beyond the scope of what clojure is trying to do. Doing validation at boundaries would be a good idea, but beyond that I wouldn’t. If you get the wrong type it’ll throw an exception anyways


Thanks for the help. I’ll stick to validation only at boundaries


is there a special operator for this?

(filter #(= (:key %) :selected-key) vector-of-maps)


@benjyz not really, altho you can achieve the same thing with comp and a set, but that's overkill unless you want to match against multiple keys at once