filter(3scm)
β¨ filter(3scm) β filter a list β¨
Okay so bestie, this is filter(3scm), the manual page for filter and partition β two procedures that are literally the main characters of list filtering. No cap. π
π LIBRARY
You can import them from either of these, depending on your setup:
(import (rnrs)) ;R6RS
(import (rnrs lists)) ;R6RS
π§Ύ SYNOPSIS
(filter proc list)
(partition proc list)
π DESCRIPTION
filter returns a list containing the elements in list for which proc returned a true value. It's giving "only the good ones make the cut." β¨
partition is exactly like filter, except it also returns a second list containing the elements that were eliminated by proc. So you get both the yeses and the nos. Iconic.
The elements of the returned lists are in the same order as they appear in list. The proc procedure is called in an unspecified order. (So like, don't assume any order, bestie. π)
Proc should accept one argument and return a single value. Proc should not mutate list. Proc is always called in the same dynamic environment as filter or partition itself. That's a key detail, iykyk. π
π RETURN VALUES
filter returns a single list. partition returns two lists. (Yes, two values. Not one. Two.) π
If this procedure returns twice (e.g. by use of call/cc) then the lists returned earlier are not mutated. No cap.
π EXAMPLES
(filter even? '(3 1 4 1 5 9 2 6))
=> (4 2 6)
(partition even? '(3 1 4 1 5 9 2 6))
=> (4 2 6) (3 1 1 5 9) ; two values
π οΈ APPLICATION USAGE
These procedures are common in functional code that works with lists. If you're doing functional stuff, you'll literally see them everywhere. Periodt. π₯
π COMPATIBILITY
These procedures are absent from reports other than R6RS. See SRFI-1 for alternatives. So if you're on a different report, check SRFI-1, okay? π¦
β οΈ ERRORS
This procedure can raise exceptions with the following condition types:
&assertion(R6RS) β The wrong number of arguments was passed or an argument was outside its domain. Examples of this are a procedureprocthat does not accept and return a single value, or a list which is circular or improper. π
So like, if your proc is weird or your list is circular or improper, expect an exception. Be careful. π«Ά
π SEE ALSO
map(3scm), remp(3scm)
π STANDARDS
R6RS
βοΈ AUTHORS
This page is part of the scheme-manpages project. It includes materials from the RnRS documents. More information can be found at https://github.com/schemedoc/manpages/. π§
π BUGS
The procedure proc should avoid side-effects, because the order of calls is unspecified. So like, don't be messy with side effects, bestie. It's giving "undefined order" energy. π
That's the whole vibe check, bestie. This page is from the scheme-manpages project, and this particular doc is dated 2021-03-03. Slay. πβ¨
π¦ where this page comes from
- nixpkgs unstable: scheme-manpages 0-unstable-2024-02-11
- π the page's license: MIT
- Copyright (c) 2021 Gwen Weinholt
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms