You are right. If it is only applied to keys, like in Thomas's example, it 
can be very helpful.

On Wednesday, January 7, 2015 11:21:39 AM UTC+2, Andrey Antukh wrote:
>
> Hello
>
> 2015-01-07 10:11 GMT+01:00 Noam Ben-Ari <nbe...@gmail.com <javascript:>>:
>
>> @Thomas
>>
>> Unfortunately, clojure.walk is not StackOverflowError-safe. Same goes for 
>> tree-seq (uses walk). The only safe solution I found so far are zippers.
>>
>> Regarding memoization, yes I agree it will help if converting the same 
>> maps frequently, however at scale, with many users hitting the same API, 
>> and each has a different user-id, it will not help (unless I'm missing 
>> something).
>>
>
> As far as I understand, you are trying transform keys and not values. If 
> that supposition is correct, you have only a little subset of posible keys 
> memoized (the set of keys of your api). In case of user-id, you will 
> memoize the transformation of userId to user-id and for it you only need 
> one cache entry.
>
> Obviously, if you transform arbitrary user input, memoize is not a good 
> solution.
>
> My two cents!
>
> Cheers.
> Andrey
>
>>
>> Thanks.
>>
>> On Wednesday, January 7, 2015 1:36:53 AM UTC+2, Thomas Heller wrote:
>>>
>>> If you want to boost performance a bit just memoize the conversion 
>>> functions. Memoize makes you vurnable to exploits though, better use 
>>> something with WeakRefs if you convert anything from untrusted sources (eg. 
>>> guava CacheBuilder). But given your usecase this will probably be the 
>>> biggest gain, no matter what else you use to convert maps.
>>>
>>> https://gist.github.com/thheller/7ddc0371561deaf13e11
>>> "Elapsed time: 35.488 msecs"
>>>
>>> clojure.walk has keywordize-keys and stringify-keys, maybe a suitable 
>>> starting point for your implementation.
>>>
>>> HTH,
>>> /thomas
>>>
>>>
>>> On Tuesday, January 6, 2015 8:25:57 PM UTC+1, Noam Ben-Ari wrote:
>>>>
>>>> Hi,
>>>>
>>>> I've written a small library (1 ns, 100 lines) to transform nested maps 
>>>> from "dash-case" keys to "camelCase" keys and back.
>>>>
>>>> The original use case was taking MySQL records that use camelCase field 
>>>> names and convert them to dash-case so they don't stick out like a sore 
>>>> thumb in my code. Similarly, when writing new records into the DB, I 
>>>> wanted 
>>>> to camelize them back before passing to JDBC.
>>>>
>>>> It should work on an arbitrarily deep nested map without blowing the 
>>>> stack (using zipper).
>>>>
>>>> It is symmetric:
>>>>
>>>> (dasherize "clientOSVersion")
>>>> => "client-OS-version"
>>>> (camelize "client-OS-version")
>>>> => "clientOSVersion"
>>>>
>>>>
>>>> The library starts with defining functions that work on strings, then 
>>>> ones that work on keywords (internally calling the string ones) and later 
>>>> ones working on maps (that assume all keys are keywords and use the 
>>>> keyword 
>>>> functions). Lastly, the library defines protocols that will ease working 
>>>> with different types.
>>>>
>>>> I would love any feedback, but especially:
>>>> - is there any off-the-shelf library for this already?
>>>> - I found zipper and regex to be really hurting performance here, 
>>>> anything you would do differently to improve this?
>>>> - anything about style... I'm writing Clojure for a year and didn't get 
>>>> much code reviews.
>>>>
>>>> the gist is here:
>>>>
>>>> https://gist.github.com/NoamB/6e940775dfa63c73ee9c
>>>>
>>>> Thanks.
>>>>
>>>> PS - I took the string versions of the functions from cuerdas (
>>>> https://github.com/funcool/cuerdas) and modified a bit, mainly to get 
>>>> the symmetry working.
>>>>
>>>  -- 
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clo...@googlegroups.com 
>> <javascript:>
>> Note that posts from new members are moderated - please be patient with 
>> your first post.
>> To unsubscribe from this group, send email to
>> clojure+u...@googlegroups.com <javascript:>
>> 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+u...@googlegroups.com <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> -- 
> Andrey Antukh - Андрей Антух - <andrei....@kaleidos.net <javascript:>> / <
> ni...@niwi.be <javascript:>>
> http://www.niwi.be <http://www.niwi.be/page/about/>
> https://github.com/niwibe
>  

-- 
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/d/optout.

Reply via email to