Skip to content

Instantly share code, notes, and snippets.

@brianfay
Created November 8, 2015 17:23
Show Gist options
  • Save brianfay/85c812a56a0129e744df to your computer and use it in GitHub Desktop.
Save brianfay/85c812a56a0129e744df to your computer and use it in GitHub Desktop.
(defn my-filter-cons
"Filter a sequence, implemented with reduce and cons"
[pred sequence]
(reduce (fn [seq x]
(if (pred x) (cons x seq) seq)) '() sequence))
(defn my-filter-conj
"Filter a sequence, implemented with reduce and conj"
[pred sequence]
(reduce (fn [seq x]
(if (pred x) (conj seq x) seq)) '() sequence))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment