# Difference between revisions of "ifp"

Line 1: | Line 1: | ||

{{DISPLAYTITLE:ifp}} | {{DISPLAYTITLE:ifp}} | ||

− | [[Type signature|Type]]: <source inline></source> | + | [[Type signature|Type]]: <source inline>ifp :: (Int -> Bool) -> (Pattern a -> Pattern a) -> (Pattern a -> Pattern a) -> Pattern a -> Pattern a</source> |

'''ifp''' decides whether to apply one or another function depending on the result of a test function, which is passed the current cycle as a number. For example: | '''ifp''' decides whether to apply one or another function depending on the result of a test function, which is passed the current cycle as a number. For example: |

## Latest revision as of 18:47, 28 April 2019

Type: `ifp :: (Int -> Bool) -> (Pattern a -> Pattern a) -> (Pattern a -> Pattern a) -> Pattern a -> Pattern a`

**ifp** decides whether to apply one or another function depending on the result of a test function, which is passed the current cycle as a number. For example:

```
d1 $ ifp ((== 0).(flip mod 2))
(striate 4)
(# coarse "24 48") $
sound "hh hc"
```

This will apply `striate 4`

for every even cycle, and `# coarse "24 48"`

for every odd one.

Detail: The test function does not rely on anything tidal-specific, it uses plain Haskell functionality for operating on numbers. That is, it calculates the modulo of 2 of the current cycle which is either 0 (for even cycles) or 1. It then compares this value against 0 and returns the result, which is either True or False. This is what the first part of `ifp`

's type signature signifies (`Int -> Bool`

), a function that takes a whole number and returns either True or False.