Fork me on GitHub
#beginners
<
2017-06-25
>
drewverlee05:06:25

How do you check if something is a collection?

drewverlee05:06:51

This seems like it should be straight foward, but everything i try seems to have edge cases where it doesn’t work.

drewverlee05:06:07

google failed me hard on that one…

colinkahn05:06:40

There is seqable?

drewverlee05:06:43

seqable? nil returns true. for reasons i’m to tired to investigate 🙂

noisesmith05:06:06

it's hard coded into it as one of the cases iirc

noisesmith05:06:14

strings are also seqable

noisesmith05:06:19

(that link is to canSeq, which seqable? calls)

colinkahn05:06:46

not built-in but something like this? (def coll? (some-fn vector? map? list?))

noisesmith05:06:13

coll? is actually built in

noisesmith05:06:42

it checks for clojure persistent collections (which include those plus set? and instance PersistentQueue)

colinkahn05:06:59

oh nvm, completely didn't realize he already answered the question 😅

drewverlee05:06:20

yea, i forgot about coll? and was trying to use seqable?

noisesmith05:06:05

for completeness you could also check for instance java.util.Collection

riptidebeach21:06:46

not sure if there’s a better channel for this, but I’m wondering if anyone has a good resource for or idiomatic example of wrapping an http api in clojure/script?

riptidebeach21:06:07

This is mainly for educational purposes; my company is mostly Scala, but we expose an http api and I’d like to practice / perhaps make internal use of this.

riptidebeach21:06:31

I’m at that intermediate point with clojure where I can tell if an interface I’m using seems idiomatic and well thought-out or not, but I haven’t worked on any libraries myself yet — so I don’t know what I don’t know 😉

alice21:06:20

And in clojurescript (what I use) cljs-http

alice21:06:27

Plenty'o examples

riptidebeach21:06:41

ok cool. I have actually used cljs-http before and it was great

riptidebeach21:06:59

maybe I didn’t phrase it right, and maybe those libraries solve my question and I need to dive into them

riptidebeach21:06:11

or maybe it’s just a wrapper design question in general (agnostic of language)

riptidebeach21:06:49

but I’m wondering: with a clojure/script library that wraps an api, I’m interested in best practices of what data types to return, how should the user interact with it (a client that can handle any verb/endpoint vs specific functions wrapping known endpoints)

riptidebeach21:06:26

reading further into those examples in case those answer my question :disappear:

alice21:06:05

It was how I interpreted your question, dw. I can't really say much as I haven't written much in the way of libraries in Clojure/script, but I can say to follow the general good clojure ideas, data driven, etc

riptidebeach22:06:50

👍 on just following clojure principles. I guess guidance with writing a library is what I’m really after

alice22:06:02

That's a topic that probably has books written on books about it

riptidebeach22:06:58

yikes! I bet. I know a good one (library) when I see one, and a bad one

riptidebeach22:06:15

but I’ve seen so many ways of tackling the problem, good and bad. Maybe a better question to have asked would have been: what others consider to be best-in-class clojure api wrappers