Function Repository Resource:

Discard

Source Notebook

Eliminate elements from a list for which a given conditional is True

Contributed by: Taliesin Beynon

ResourceFunction["Discard"][list, crit]

discards elements of list for which crit[elem] gives True.

ResourceFunction["Discard"][crit]

is an operator form of ResourceFunction["Discard"] that can be applied to an expression.

Details and Options

ResourceFunction["Discard"][list,crit] is equivalent to Select[list,Not[TrueQ[crit]]].

Examples

Basic Examples (1) 

Discard all primes from a list of integers:

In[1]:=
ResourceFunction["Discard"][PrimeQ][{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}]
Out[1]=

Properties and Relations (1) 

If crit[elem] does not explicitly evaluate to False, elem is kept:

In[2]:=
ResourceFunction["Discard"][Range[10], Which[
   Mod[#, 3] === 0, True, Mod[#, 3] === 1, False,
   Mod[#, 3] === 2, Indeterminate
   ] &]
Out[2]=

Requirements

Wolfram Language 11.3 (March 2018) or above

Version History

  • 1.0.0 – 13 December 2018

License Information