Hmm, I see. get-distinct was returning an empty lazyseq, which apparently 
made the difference. 


On Sunday, December 22, 2013 2:56:01 PM UTC-5, larry google groups wrote:
>
> Hmm, the different return types seem tied to the 2 different functions 
> being called, but both functions have the same return type, which is a 
> lazyseq. I am using Monger to get data from MongoDb. These functions are 
> private:
>
> (defn- get-distinct [request]
>   {:pre [(= (type request) clojure.lang.PersistentHashMap)]
>    :post [(= (type %) clojure.lang.LazySeq)]}
>   (monger/get-distinct (:item-type request))) 
>
> (defn- paginate-results [request]
>   {:pre [ (= (type request) clojure.lang.PersistentHashMap)]
>    :post [(= (type %) clojure.lang.LazySeq)]}
>   (monger/paginate-results (:item-type request) (if (:which-page request)
>                                                   (:which-page request)
>                                                   0))) 
>
> Both of these functions return lazyseqs, as expected. The results from 
> both get run through a (reduce) function that does some minor filtering. 
> Yet in one case the return type (from the reduce function) 
> is clojure.lang.PersistentArrayMap and in the other it 
> is clojure.lang.PersistentHashMap. I'd like to be able to write a :post 
> condition that enforces strictness, but that seems impossible because I can 
> not figure out what the rule is that handles the conversion. I don't care 
> if the return type is clojure.lang.PersistentArrayMap 
> or clojure.lang.PersistentHashMap, all I want is it for it be consistently 
> one or the other. 
>
>
>
>
>
> On Sunday, December 22, 2013 2:31:45 PM UTC-5, larry google groups wrote:
>>
>>
>> I am surprised that a map literal is clojure.lang.PersistentArrayMap but 
>> as soon as I assign it to a var, it becomes clojure.lang.PersistentHashMap. 
>> Are there any rules for being able to predict when these conversions occur? 
>>
>> user> (type {})
>> clojure.lang.PersistentArrayMap
>>
>> user> (type {:what "why?"})
>> clojure.lang.PersistentArrayMap
>>
>> user> (def curious {:what "why?"})
>> #'user/curious
>>
>> user> (type curious)
>> clojure.lang.PersistentHashMap
>>
>> user> (def sug (assoc curious :whodoneit "mikey"))
>> #'user/sug
>>
>> user> (type sug)
>> clojure.lang.PersistentHashMap
>>
>> I am curious because I wrote a (reduce) function which mostly just builds 
>> a map: 
>>
>>      (assoc map-of-data (:item-name next-item) next-item))
>>
>> Since I was using assoc I was certain I would 
>> get clojure.lang.PersistentHashMap back, but instead I 
>> got clojure.lang.PersistentArrayMap. 
>>
>>
>>
>>
>>
>>
>>

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to