This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-08-25
Channels
- # admin-announcements (3)
- # alda (2)
- # beginners (10)
- # boot (44)
- # cider (31)
- # cljs-dev (5)
- # cljsjs (2)
- # cljsrn (17)
- # clojure (181)
- # clojure-austin (2)
- # clojure-brasil (18)
- # clojure-canada (1)
- # clojure-conj (5)
- # clojure-dev (11)
- # clojure-gamedev (30)
- # clojure-russia (380)
- # clojure-spec (50)
- # clojure-uk (35)
- # clojurescript (146)
- # clojutre (1)
- # component (1)
- # cursive (62)
- # datomic (27)
- # dirac (7)
- # editors (23)
- # emacs (7)
- # events (34)
- # funcool (22)
- # hoplon (134)
- # jobs (22)
- # jobs-rus (7)
- # juxt (1)
- # kekkonen (1)
- # lein-figwheel (54)
- # leiningen (7)
- # luminus (2)
- # off-topic (5)
- # om (4)
- # onyx (27)
- # proton (5)
- # protorepl (2)
- # re-frame (16)
- # reagent (29)
- # rethinkdb (2)
- # schema (1)
- # untangled (61)
- # yada (9)
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$java.io.OutputStream$ff19274a clojure.lang.Reflector.invokeMatchingMethod (Reflector.java:80)
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