Re: camelize-dasherize - reinventing the wheel?

2015-01-07 Thread Noam Ben-Ari
Cool! I'm glad you found it useful :-)

On Wednesday, January 7, 2015 2:12:35 AM UTC+2, Andrey Antukh wrote:
>
> Hi!
>
> 2015-01-06 20:25 GMT+01:00 Noam Ben-Ari >:
>
>> 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.
>>
>
> I have ported some changes from your dasherize version to cuerdas. Thank 
> you very much for improved version.
>
> Cheers.
> Andrey
>  
>
>>  -- 
>> 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 
>> 
>> 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 
>> 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 .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> -- 
> Andrey Antukh - Андрей Антух - > / <
> ni...@niwi.be >
> http://www.niwi.be 
> 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.


Re: camelize-dasherize - reinventing the wheel?

2015-01-07 Thread Noam Ben-Ari
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 >:
>
>> @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 
>> 
>> 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 
>> 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 .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> -- 
> Andrey Antukh - Андрей Антух - > / <
> ni...@niwi.be >
> http://www.niwi.be 
> 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 unsubscr

Re: camelize-dasherize - reinventing the wheel?

2015-01-07 Thread Andrey Antukh
Hello

2015-01-07 10:11 GMT+01:00 Noam Ben-Ari :

> @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 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.
>



-- 
Andrey Antukh - Андрей Антух -  / 
http://www.niwi.be 
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.


Re: camelize-dasherize - reinventing the wheel?

2015-01-07 Thread Noam Ben-Ari
@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).

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 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.


Re: camelize-dasherize - reinventing the wheel?

2015-01-06 Thread Andrey Antukh
Hi!

2015-01-06 20:25 GMT+01:00 Noam Ben-Ari :

> 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.
>

I have ported some changes from your dasherize version to cuerdas. Thank
you very much for improved version.

Cheers.
Andrey


>  --
> 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.
>



-- 
Andrey Antukh - Андрей Антух -  / 
http://www.niwi.be 
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.


Re: camelize-dasherize - reinventing the wheel?

2015-01-06 Thread Thomas Heller
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 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.


Re: camelize-dasherize - reinventing the wheel?

2015-01-06 Thread Noam Ben-Ari
Thanks for this, Andy.

I see it uses postwalk and recursion for nested maps, so it will eventually 
blow up the stack. Probably faster than a zipper though.
Also, for changing case it uses a custom split and join instead of regex, a 
very interesting approach.

I won't be using it directly though because it has some issues with 
uberwar, but I can learn from it.

On Tuesday, January 6, 2015 9:45:59 PM UTC+2, Andy Fingerhut wrote:
>
> I have not used it, but from the docs it appears there is at least some 
> overlap with this library:
>
> https://github.com/qerub/camel-snake-kebab
>
> It mentions in its docs that it avoids using regex's.
>
> Andy
>
> On Tue, Jan 6, 2015 at 11:25 AM, 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 
>> 
>> 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 
>> 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 .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
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.


Re: camelize-dasherize - reinventing the wheel?

2015-01-06 Thread Andy Fingerhut
I have not used it, but from the docs it appears there is at least some
overlap with this library:

https://github.com/qerub/camel-snake-kebab

It mentions in its docs that it avoids using regex's.

Andy

On Tue, Jan 6, 2015 at 11:25 AM, 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 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.
>

-- 
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.