Saturday, 15 June 2013

clojure - Is there a simpler way that this to get each element of a sequence, paired with "its" tail? -


I think that a sequence of "elements" needs to be changed in the order of "pair", in which the first element Is the element of the initial sequence, and the second element is the tail of the initial sequence from that element.

(A BCDE) - & gt; (A (BCD) (B (CDE)) (C) (D (E)) (E ()))

I have written it:

  (remove head and tail) (cond (empty): and (opposition (list (first) (rest) (head and tail)))   

Is a simple combination built into functions or functions that can do it more easily?

Here's an approach:

  (let [x [1 (3 (4)) (4 ())] (map list X (rest xs again)) = ((1 (2 3 4)) (2 (3) 4) / Code>  

This can be tailored to your needs, for example you can like the map vector to map list etc.. / P>

In addition, about head and tail impl: from the question text: Written as well as two types of branches cond an Will / to >.

No comments:

Post a Comment