Skip to content

Instantly share code, notes, and snippets.

@francoisdevlin
Created August 8, 2009 04:07
Show Gist options
  • Save francoisdevlin/164291 to your computer and use it in GitHub Desktop.
Save francoisdevlin/164291 to your computer and use it in GitHub Desktop.
;These tests are how Sean Devlin proposes that this function should behave.
(deftest test-flatten-proposed
(are [expected nested-val] (= (flatten nested-val) expected)
;simple literals
nil nil
1 1
'foo 'foo
:keyword :keyword
1/2 1/2
#"[\r\n]" #"[\r\n]"
true true
false false
"bar" "bar"
;vectors
[] []
[1 2 3 4 5] [[1 2] [3 4 [5]]]
[1 2 3 4 5] [1 2 3 4 5]
[1 2 3 4 5] [#{1 2} 3 4 5]
;sets
[] #{}
[1 2 3 4 5] #{#{1 2} 3 4 5}
;lists
[] '()
[1 2 3 4 5] '(1 2 3 4 5)
[1 2 3 4 5] '(#{1 2} 3 4 5)
;maps
[:a 1 :b 2] {:a 1 :b 2}
[:a :b 1 :c 2] {[:a :b] 1 :c 2}
[:a 1 2 :b 3] {:a [1 2] :b 3}
;fns
count count))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment