member-if: Searching for tails of sequences

Description Usage Arguments Details Value See Also Examples

Description

member.if and member.if.not search "sequences" (by which we mean lists, other vectors or pairlists) for the first element satisfying some predicate function, and return the sub-sequence beginning with that element. member.if.not uses Negate(f) as its predicate.

Usage

1
2
3
member.if(f, x, k = identity)

member.if.not(f, x, k = identity)

Arguments

f

The filter predicate to use on the sequence x.

x

The sequence to search for a satisfying element.

k

The "key" function to pre-apply to elements of x. Defaults to the identity function.

Details

The sequence searched is actually map(k, x) rather than x, which makes it easier to avoid defining short anonymous functions.

Value

The tail of the sequence map(k, x) beginning with the first element that satisfies the predicate f, or NULL if no element did.

See Also

The functional-programming functions in base, especially Filter, under funprog.

Examples

1
2
3
4
5
6
7
f <- 20:40

#The first element divisible by 3 and all afterward
member.if(is.zero, f, k=function(x) x %% 3) == 21:40

#Trimming by the presence of a sentinel value
member.if.not(function(x) x < 30, f) == 30:40

wwbrannon/schemeR documentation built on May 4, 2019, 12:03 p.m.