On Feb 24, 10:30 pm, ".Bill Smith" <william.m.sm...@gmail.com> wrote: > I finally got around to writing an "unbean" function. As the name > suggests, it's the reverse of the bean function: it takes a class and > a map of property name/values and returns an instance of that class > with those property values. So for example, if class House has > properties "address", "color", and "area", you can do this: > > user=> (def h (unbean House {:address "100 Elm Street" :color > "red" :area 2500})) > #'user/h > user=> (.getAddress h) > "100 Elm Street" > user=> (bean h) > {:address "100 Elm Street", :color "red", :area 2500} > user=> >
I tend to associate "bean" with Java beans, so the naming seems to be reversed IMHO: "bean" should convert a Clojure map to a Java bean, and "unbean" should do the reverse. In Scheme-speak they would be map->bean and bean->map, which might be a bit verbose. It's getting late here so I don't have time to test, but would a recursive map be converted to a recursive bean (i.e. some elements are themselves beans) and vice versa with your functions? Regards, -- Michel --~--~---------~--~----~------------~-------~--~----~ 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 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 -~----------~----~----~----~------~----~------~--~---