Release: v0.7.0
This release comes with a lot a small improvements to the core library.
Merge datastructures
Merging maps or nested data structures is a common problem in programming. The new functions merge-with
and deep-merge
solve these problems in Phel.
The first function merge-with
takes a two-arity function f
and a unlimited number of hash maps. It will merge these hash maps as in merge
but in case two maps have the same key it will call f
with the left and the right value. Example:
(merge-with + {:a 1 :b 2} {:b 3 :c 4}) # Evaluates to {:a 1 :b 5 :c 4}
The second function deep-merge
will recursively merge nested data structures. Hash maps will be merged as in merge
, vectors will be concatenated and sets will be united. Example:
(deep-merge {:a {:b {:c [:d]}}} {:a {:b {:c [:e] :f :g}}} # Evaluates to {:a {:b {:c [:d :e] :f :g}}}
Improved phel\http namespace
The namespace phel\http
go a little facelift:
- The function
http/uri-from-string
was added. This lets you create a URI struct from a string - The function
http/response-from-map
was added. This function create a response struct from a hash map. - The function
http/response-from-string
was added. This function creates a response from a string function. - The request struct got a new additional field:
attributes
. This field can be used store custom data to enrich a request. - The function
http/request-from-map
was added. This function create a request struct from a hash map.
Read, eval and compile
The core library has now some additional function to call parts of the compiler directly in your code.
First, the read-string
function will parse a string and return a Phel expression.
(read-string "(+ 1 1)") # Evaluates to '(+ 1 1)
Second, the eval
function let's you evaluate a Phel expression:
(eval '(+ 1 1)) # Evaluates to 2
Finally, the compile
function returns the compiled PHP code for a give Phel expression:
(compile '(+ 1 1)) # Evaluates to "(1 + 1);"
Other changes
A few other changes and bug fixes have been done in this version. For a full list of changes have a look at the Changelog.