{"size": 979, "ext": "scrbl", "max_stars_repo_path": "lens-doc/unstable/lens/set-filterer.scrbl", "max_stars_repo_name": "AlexKnauth/lens", "max_stars_repo_stars_event_min_datetime": "2015-07-08T12:56:46.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T21:21:54.000Z", "max_issues_repo_path": "lens-doc/unstable/lens/set-filterer.scrbl", "max_issues_repo_name": "AlexKnauth/lens", "max_issues_repo_issues_event_min_datetime": "2015-07-07T01:47:59.000Z", "max_issues_repo_issues_event_max_datetime": "2019-09-10T18:35:17.000Z", "max_forks_repo_path": "lens-doc/unstable/lens/set-filterer.scrbl", "max_forks_repo_name": "AlexKnauth/lens", "max_forks_repo_forks_event_min_datetime": "2015-07-07T05:01:29.000Z", "max_forks_repo_forks_event_max_datetime": "2019-07-16T00:37:04.000Z"}
{"max_stars_count": 66, "max_issues_count": 199, "max_forks_count": 11, "avg_line_length": 40.7916666667, "max_line_length": 95, "alphanum_fraction": 0.657814096}
#lang scribble/manual

@(require lens/private/doc-util/main)

@title{Filtering sets}

@defproc[(set-filterer-lens [pred (-> any/c any/c)]) (lens/c functional-set? functional-set?)]{
Creates a lens that filters a set by the predicate @racket[pred].
@lens-unstable-examples[
  (lens-view (set-filterer-lens number?) (set 1 'a 2 'b 'c 3 'd 'e))
  (lens-set (set-filterer-lens number?) (set 1 'a 2 'b 'c 3 'd 'e) (set 4 5 6 7))
]
Lists are also sets, so @racket[set-filterer-lens] works for lists too, but it
does not preserve ordering. It follows the lens laws only if you compare using
@racket[set=?], not @racket[equal?].
@lens-unstable-examples[
  (lens-view (set-filterer-lens number?) '(a 1 2 3)) ; will be '(1 2 3)
  (lens-set (set-filterer-lens number?) '(a 1 2 3) '(1 2 3)) ; will be '(3 2 1 a)
  (code:comment "this breaks the lens laws according to equal?")
  (equal? '(a 1 2 3) '(3 2 1 a))
  (code:comment "but not according to set=?")
  (set=? '(a 1 2 3) '(3 2 1 a))
]}
