Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add koans for partition function

  • Loading branch information...
commit 626f97de8f63a61c7e4e8a120e50005cb35f9578 1 parent f1ee68a
@ignacy ignacy authored trptcolin committed
View
1  ideaboard.txt
@@ -15,7 +15,6 @@ Particular Functions
fnil - creating_a_function
juxt - creating_a_function
constantly - creating_a_function
-partition
flatten
frequencies
View
9 resources/koans.clj
@@ -196,4 +196,11 @@
]
"___" [#(.toUpperCase %)
]
- }]]
+ }]
+ ["20_partition" {"__" [partition
+ [:a :b :c]
+ '((0 1 2) (3 4))
+ 5
+ :hello
+ (6 :this :are)
+ ]}]]
View
18 src/koans/20_partition.clj
@@ -0,0 +1,18 @@
+(meditations
+ "To split a collection you can use the partition function"
+ (= '((0 1) (2 3)) (__ 2 (range 4)))
+
+ "But watch out if there is not enough elements to form n sequences"
+ (= '(__) (partition 3 [:a :b :c :d :e]))
+
+ "You can use partition-all to also get partitions with less then n elements"
+ (= __ (partition-all 3 (range 5)))
+
+ "If you need to, you can start each sequence with an offset"
+ (= '((0 1 2) (5 6 7) (10 11 12)) (partition 3 __ (range 13)))
+
+ "Consider padding the last sequence with some default values.."
+ (= '((0 1 2) (3 4 5) (6 :hello)) (partition 3 3 [__] (range 7)))
+
+ ".. but notice that they will only pad up to given sequence length"
+ (= '((0 1 2) (3 4 5) __) (partition 3 3 [:this :are "my" "words"] (range 7))))
Please sign in to comment.
Something went wrong with that request. Please try again.