I am trying to write a Clojure utility utility called map-longest (alternate name score). This function will have the following "signature":
(map-longest fun missing-value-seq c1 & colls)
and will behave similarly to map , except that it will continue to process the collected collections until the longest is exhausted. For collections, shorter than the longest, when it ends with values, it takes them from missing-values-seq . It should be lazy, but obviously cannot be used with endless collections.
Usage example:
(print (apply str (map-longest #(str %1 \space %2 \space %3 \newline) (repeatedly "--") ["a1" "a2" "a3"] ["b1" "b2"] ["c1" "c2" "c3" "c4"])))
He should create the following output:
a1 b1 c1 a2 b2 c2 a3 -- c3 -- -- c4
but I may have the wrong call.
How to implement this? Does the clojure.core library or clojure -contrib already have something like this? As an alternative to missing-value-seq , would it be better to pass a second function to generate missing values (for example: #(identity "--") in my example)?
Use case: I write a little spider solitaire in the form of exercises when learning Clojure / functional programming. I need to display game tables (tables for purists :-)).
clojure map
Ralph
source share