Module

# Data.Function

Package
purescript-prelude
Repository
purescript/purescript-prelude

### #flipSource

``flip :: forall c b a. (a -> b -> c) -> b -> a -> c``

Flips the order of the arguments to a function of two arguments.

``````flip const 1 2 = const 2 1 = 2
``````

### #constSource

``const :: forall b a. a -> b -> a``

Returns its first argument and ignores its second.

``````const 1 "hello" = 1
``````

### #applySource

``apply :: forall b a. (a -> b) -> a -> b``

Applies a function to an argument. This is primarily used as the operator `(\$)` which allows parentheses to be omitted in some cases, or as a natural way to apply a chain of composed functions to a value.

### #(\$)Source

Operator alias for Data.Function.apply (right-associative / precedence 0)

Applies a function to an argument: the reverse of `(#)`.

``````length \$ groupBy productCategory \$ filter isInStock \$ products
``````

is equivalent to:

``````length (groupBy productCategory (filter isInStock products))
``````

Or another alternative equivalent, applying chain of composed functions to a value:

``````length <<< groupBy productCategory <<< filter isInStock \$ products
``````

### #applyFlippedSource

``applyFlipped :: forall b a. a -> (a -> b) -> b``

Applies an argument to a function. This is primarily used as the `(#)` operator, which allows parentheses to be ommitted in some cases, or as a natural way to apply a value to a chain of composed functions.

### #(#)Source

Operator alias for Data.Function.applyFlipped (left-associative / precedence 1)

Applies an argument to a function: the reverse of `(\$)`.

``````products # filter isInStock # groupBy productCategory # length
``````

is equivalent to:

``````length (groupBy productCategory (filter isInStock products))
``````

Or another alternative equivalent, applying a value to a chain of composed functions:

``````products # filter isInStock >>> groupBy productCategory >>> length
``````

### #applyNSource

``applyN :: forall a. (a -> a) -> Int -> a -> a``

`applyN f n` applies the function `f` to its argument `n` times.

If n is less than or equal to 0, the function is not applied.

``````applyN (_ + 1) 10 0 == 10
``````

### #onSource

``on :: forall c b a. (b -> b -> c) -> (a -> b) -> a -> a -> c``

The `on` function is used to change the domain of a binary operator.

For example, we can create a function which compares two records based on the values of their `x` properties:

``````compareX :: forall r. { x :: Number | r } -> { x :: Number | r } -> Ordering
compareX = compare `on` _.x
``````

## Re-exports from Control.Category

### #composeSource

``compose :: forall a d c b. Semigroupoid a => a c d -> a b c -> a b d``

### #identitySource

``identity :: forall a t. Category a => a t t``

### #(>>>)Source

Operator alias for Control.Semigroupoid.composeFlipped (right-associative / precedence 9)

### #(<<<)Source

Operator alias for Control.Semigroupoid.compose (right-associative / precedence 9)
{"ft_lang_label":"__label__en","ft_lang_prob":0.60753906,"math_prob":0.8484219,"size":3146,"snap":"2023-14-2023-23","text_gpt3_token_len":866,"char_repetition_ratio":0.15658817,"word_repetition_ratio":0.13818182,"special_character_ratio":0.2759059,"punctuation_ratio":0.19005328,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.97493404,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-05-31T03:51:08Z\",\"WARC-Record-ID\":\"<urn:uuid:a74efeb3-3069-4ad0-82e1-329a61311643>\",\"Content-Length\":\"22814\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:da8981fe-7df6-4ca9-93d9-e30487b12ab7>\",\"WARC-Concurrent-To\":\"<urn:uuid:c0a1ef4a-1794-4d37-9d9d-c0ec5e081bc0>\",\"WARC-IP-Address\":\"206.189.189.151\",\"WARC-Target-URI\":\"https://pursuit.purescript.org/packages/purescript-prelude/4.1.0/docs/Data.Function\",\"WARC-Payload-Digest\":\"sha1:VMQVKIJXGMFBPZDWYAMI5P6S247XTEHJ\",\"WARC-Block-Digest\":\"sha1:AJQMRX7QNYPM3QJE7FEXYMFIQVH45LW6\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-23/CC-MAIN-2023-23_segments_1685224646257.46_warc_CC-MAIN-20230531022541-20230531052541-00602.warc.gz\"}"}