Permalink
Browse files

Implemented group-triplet using take/drop

  • Loading branch information...
1 parent 6a9c8fa commit 2b643f7b5bc867cdb559c4506cbe88e070af1ec5 Andrey Paramonov committed Oct 24, 2012
Showing with 5 additions and 4 deletions.
  1. +1 −1 README.md
  2. +4 −3 src/dojo/parens.clj
View
@@ -28,7 +28,7 @@ Clojure STM in action.
## Inserting parentheses
-List manipulations example.
+Lists and symbols [manipulation](blob/master/test/dojo/parens_test.clj).
## Usage
View
@@ -7,9 +7,10 @@
(f (positions (set items) coll)))
(defn group-triplet [coll idx]
- (concat (take (dec idx) coll)
- (list (map #(nth coll %) [(dec idx) idx (inc idx)]))
- (drop (+ 2 idx) coll)))
+ (let [li (- idx 1), ri (+ idx 2)]
+ (concat (take li coll)
+ (list (->> coll (take ri) (drop li)))
+ (drop ri coll))))
(defn group-terms [pos operators coll]
(if-let [i (index pos operators coll)]

0 comments on commit 2b643f7

Please sign in to comment.