<commit_before>..  Copyright © <NAME>
.. |---| unicode:: U+2014  .. em dash, trimming surrounding whitespace
   :trim:

Manipulating Collections - filter and partial
::::::::::::::::::::::::::::::::::::::::::::::::::::::

The ``filter`` function processes a collection and yields a sequence of the items that fit certain criteria.


Here is the general form of the ``filter`` function that we will use:

::

    (reduce predicate collection)
    
where

* ``predicate`` is a function that has one parameter: the collection item under consideration
* ``collection`` is the collection to be filtered.

``filter`` applies the ``predicate`` function to each item in the collection. If the function returns ``true``, the item goes into the output sequence, otherwise it doesn’t.

As an example, here is ``filter`` used to extract only numbers that are multiples of four:
    
.. activecode:: filter_fours
    :caption: Filter example
    :language: clojurescript
    
    (defn multiple-of-four? [value]
        (= (rem value 4) 0))
    
    (filter multiple-of-four? [2 16 -3 -72 128 99] )


.. note::
    By convention, boolean functions (functions that return ``true`` or ``false```) have
    names ending with a question mark. Some of the built-in predicates in ClojureScript
    are ``even?``, ``odd?``, ``pos?`` (positive), ``neg?`` (negative), ``zero?``, and ``empty?`` (tests
    if a collection is empty or not).
    <commit_msg>Fix typo (extra backtick).<commit_after>..  Copyright © <NAME>
.. |---| unicode:: U+2014  .. em dash, trimming surrounding whitespace
   :trim:

Manipulating Collections - filter and partial
::::::::::::::::::::::::::::::::::::::::::::::::::::::

The ``filter`` function processes a collection and yields a sequence of the items that fit certain criteria.


Here is the general form of the ``filter`` function that we will use:

::

    (reduce predicate collection)
    
where

* ``predicate`` is a function that has one parameter: the collection item under consideration
* ``collection`` is the collection to be filtered.

``filter`` applies the ``predicate`` function to each item in the collection. If the function returns ``true``, the item goes into the output sequence, otherwise it doesn’t.

As an example, here is ``filter`` used to extract only numbers that are multiples of four:
    
.. activecode:: filter_fours
    :caption: Filter example
    :language: clojurescript
    
    (defn multiple-of-four? [value]
        (= (rem value 4) 0))
    
    (filter multiple-of-four? [2 16 -3 -72 128 99] )


.. note::
    By convention, boolean functions (functions that return ``true`` or ``false``) have
    names ending with a question mark. Some of the built-in predicates in ClojureScript
    are ``even?``, ``odd?``, ``pos?`` (positive), ``neg?`` (negative), ``zero?``, and ``empty?`` (tests
    if a collection is empty or not).
    
{'fraction_non_alphanumeric': 0.1507991660875608, 'fraction_numerical': 0.0118137595552467, 'mean_word_length': 3.742998352553542, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6410007', 'n_tokens_mistral': 802, 'n_tokens_neox': 759, 'n_words': 359}