In programming, there's time when we have 2 arrays and we want values at the same index of both arrays to have operation on each other producing an array of result. In imperative style, we have to setup a temporary counter variable to store index the current operation is on, increment it until reaching the last value of an array. For example, we want to sum values of each index.
In functional style, there's a function called 'zip' (Haskell, Ruby) which allows us to pair up values of each index preparing to apply operation on each pair later.
In Haskell, there's even 'zipWith' which apply operation on the pair immediately instead of producing an intermediate array.
But when it comes to Clojure, I wasn't be able to find a function in its standard library with the same behavior. The closest I could find is 'zipmap' that returns back a map which is not exactly what I want. We definitely can work around a little bit to get a vector.
But as you can see, it doesn't preserve the order of an original vectors.
The next idea I have is to use 'interleave' and 'partition'
It's kinda work, but the fact that we have to call 2 functions is not so satisfied.
I went look up and found this Stack Overflow answer. Yes. Just use simple 'map'!
I think, I overlooked this solution because in Ruby, the language the I'm most comfortable with, 'map' can only operate on only one array.
Learning that Clojure's map can takes any number of collections is an aha moment for me. So now I can sum elements of more than 2 vectors easily.
Since the second argument can accept any function, creating Clojure records is as easy as this.
This link and this link explain it really well and concise
Formatting Run this command in shell sudo cpan JSON::XS Put this line to ~/.vimrc map <leader> jt <Esc> : %! json_xs -f json ...
sudo su postgres supply your Mac password modify /Library/PostgreSQL/9.x/data/pg_hba.conf from local all all md5 to local all all ...
This error message from chef is not very useful FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit ...