Skip to content

Instantly share code, notes, and snippets.

@fabioyamate
Last active December 15, 2015 11:18
Show Gist options
  • Save fabioyamate/5251624 to your computer and use it in GitHub Desktop.
Save fabioyamate/5251624 to your computer and use it in GitHub Desktop.
Given a list of list of integers, return the first item in each sublist, in a way that no duplication is occurred
(defn add-first-uniq [target coll]
(cond (not (contains? target (first coll)))
(conj target (first coll))
:else
(add-first-uniq target (rest coll))))
(reduce add-first-uniq
#{}
'((1 2 3) (1 2) (4 5)))
; => #{1 2 4}
(facts
(f '((1 4 5) (1 4 2) (10 4 1))) => '(1 4 10)
(f '()) => '()
(f '((1 2) () (3 4))) => (1 3))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment