Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I added some arguments to TXR Lisp's hash-uni (which merges two dictionaries) to be able to do this. It already has an optional join function to resolve values with clashing keys. Now it will take two additional functions to map the left and right values.

If we have a pair of dicts with values that we'd like to list, we can do [hash-uni h1 h2 append list list]. The values are turned into lists, and clashes resolved with append.

A list of hashes could be merged into lists with left-reduce, like this.

  [reduce-left (op hash-uni @1 @2 append : list) hashes #H()]
Our initial value is an empty hash #H(). The reduce kernel function is hash-uni. The values of every has in hlist are turned into one element lists, and then accumulated onto the lists in the hash merged so far with append. The initial accumulator is the empty hash.

It's more than vaguely monadic: the two functions are like "unit" and so on.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: