Skip to content

Instantly share code, notes, and snippets.

@mattmoss
Created November 1, 2012 02:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattmoss/3991188 to your computer and use it in GitHub Desktop.
Save mattmoss/3991188 to your computer and use it in GitHub Desktop.
Given two sequences of equal length and corresponding items, can one sequence be filtered based on (a predicate fn applied to) the second?
;; Given two sequences (seq-a and seq-b) of equal length and corresponding
;; items, can one sequence be filtered according to a predicate function (pred?)
;; applied to the second?
(map second
(filter #(pred? (first %))
(map list seq-a seq-b)
@mattmoss
Copy link
Author

mattmoss commented Nov 1, 2012

(for [[a b] (map list a-seq b-seq) :when (pred? a)] b)

@mattmoss
Copy link
Author

mattmoss commented Nov 1, 2012

(keep (fn [[a b]] (if (pred? b) a)) (map vector a-seq b-seq))

But this is a problem if b-seq can contain nil as a legitimate value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment