Fork me on GitHub
#pedestal
<
2017-01-23
>
martinklepsch07:01:54

In the interceptor code: Is there a good reason peek is used to obtain the first item of the stack? It’s a list so first should be just as good? https://github.com/pedestal/pedestal/blob/0.5.2/interceptor/src/io/pedestal/interceptor/chain.clj#L246

martinklepsch07:01:38

I’m doing some, ahem, adventurous stuff I guess and modify the stack (appending something) which the usage of peek complicates because it explicitly requires a PersistentList and anything that comes out of concat is LazySeq/Cons

ddeaguiar14:01:44

@martinklepsch I can only speculate that it's used to decouple the semantics of the operation from the underlying collection type. Is laziness an important property of your implementation?

martinklepsch14:01:29

@ddeaguiar Hey 🙂 laziness is not important, appending is. I ended up using something like this:

(defn concat-stack [l1 l2]
  ;; (into '(4 5) (reverse '(1 2 3))) ; => '(1 2 3 4 5)
  (into l2 (reverse l1)))

martinklepsch14:01:01

@ddeaguiar I was initially thinking “oh maybe this should be a PersistentQueue” as well but has repercussions into many places and complicates adding to the front

martinklepsch14:01:49

@ddeaguiar trying to think of a reason you’d want this decoupled from collection type but when would the stack be something else than a PersistentList?

ddeaguiar14:01:48

Yeah, so I'm just speculating. Perhaps @mtnygard could clarify. Unfortunately I personally have not done much work requiring manipulation of the interceptor chain.

ddeaguiar14:01:53

@martinklepsch I had a quick conversation with Paul deGrandis about this. Although the underlying collection type of the stack doesn't change, that's an implementation detail. The current implementation should still work if you changed the collection types of ::queue and ::stack dynamically.

martinklepsch14:01:27

@ddeaguiar to what type would I change it? PersistentQueue is the only one that supports pop/peek afaik?

martinklepsch14:01:41

Good to know you’re sitting close to the source heh 🙂

ddeaguiar14:01:31

peek/pop work with lists, queues and vectors

martinklepsch14:01:37

right vectors but then the code uses conj to add items to the stack 🙂

martinklepsch14:01:55

(so vectors are out)

martinklepsch14:01:16

> PersistentQueue is the only one that supports pop/peek afaik? should have included PersistentList

martinklepsch14:01:05

You could change it to PersistentQueue which would make some sense I guess (I can’t track down the repercussions mentioned earlier, maybe they were in my code not the interceptor code)

martinklepsch15:01:25

Either way, this is complaining at a high level, I solved my problem in an acceptable way so no need to discuss more unless more people think it’s irritating

ddeaguiar15:01:03

Well, thanks for bringing this up. I'm very interested in seeing how your work progresses!

martinklepsch15:01:34

So far interceptors are holding up nicely (and I think I’ve abused them a fair bit 🙂)