Difference between revisions of "every"

From TidalCycles userbase
Jump to: navigation, search
(Marked this version for translation)
 
Line 1: Line 1:
 
<languages/>
 
<languages/>
 
<translate>
 
<translate>
 +
<!--T:1-->
 
{{DISPLAYTITLE:every}}  
 
{{DISPLAYTITLE:every}}  
 
[[Type signature|Type]]: <syntaxhighlight lang="haskell" inline>every :: Pattern Int -> (Pattern a -> Pattern a) -> Pattern a -> Pattern a</syntaxhighlight>
 
[[Type signature|Type]]: <syntaxhighlight lang="haskell" inline>every :: Pattern Int -> (Pattern a -> Pattern a) -> Pattern a -> Pattern a</syntaxhighlight>
  
 +
<!--T:2-->
 
'''every''' is function, that allows you to apply another function conditionally. It takes three inputs, how often the function should be applied (e.g. <syntaxhighlight lang="haskell" inline>3</syntaxhighlight> to apply it every 3 cycles), the function to be applied, and the pattern you are applying it to.  
 
'''every''' is function, that allows you to apply another function conditionally. It takes three inputs, how often the function should be applied (e.g. <syntaxhighlight lang="haskell" inline>3</syntaxhighlight> to apply it every 3 cycles), the function to be applied, and the pattern you are applying it to.  
  
 +
<!--T:3-->
 
For example to reverse a pattern every three cycles (and for the other two play it normally):
 
For example to reverse a pattern every three cycles (and for the other two play it normally):
  
 +
<!--T:4-->
 
<syntaxhighlight lang="haskell">
 
<syntaxhighlight lang="haskell">
 
d1 $ every 3 rev $ n "0 1 [~ 2] 3" # sound "arpy"
 
d1 $ every 3 rev $ n "0 1 [~ 2] 3" # sound "arpy"
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 +
<!--T:5-->
 
Note that if the function you're applying requires additional parameters itself (such as <syntaxhighlight lang="haskell" inline>fast 2</syntaxhighlight> to make a pattern twice as fast), then you'll need to wrap it in parenthesis, like so:
 
Note that if the function you're applying requires additional parameters itself (such as <syntaxhighlight lang="haskell" inline>fast 2</syntaxhighlight> to make a pattern twice as fast), then you'll need to wrap it in parenthesis, like so:
  
 +
<!--T:6-->
 
<syntaxhighlight lang="haskell">
 
<syntaxhighlight lang="haskell">
 
d1 $ every 3 (fast 2) $ n "0 1 [~ 2] 3" # sound "arpy"
 
d1 $ every 3 (fast 2) $ n "0 1 [~ 2] 3" # sound "arpy"
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 +
<!--T:7-->
 
Otherwise, the <syntaxhighlight lang="haskell" inline>every</syntaxhighlight> function will think it is being passed too many parameters.
 
Otherwise, the <syntaxhighlight lang="haskell" inline>every</syntaxhighlight> function will think it is being passed too many parameters.
  
 +
<!--T:8-->
 
See also [[every']].
 
See also [[every']].
  
 +
<!--T:9-->
 
[[Category:Functions]] [[Category:Higher-order functions]] [[Category:Conditional Transformers]]
 
[[Category:Functions]] [[Category:Higher-order functions]] [[Category:Conditional Transformers]]
 
</translate>
 
</translate>

Latest revision as of 23:26, 17 December 2019

Other languages:
English • ‎français

Type: every :: Pattern Int -> (Pattern a -> Pattern a) -> Pattern a -> Pattern a

every is function, that allows you to apply another function conditionally. It takes three inputs, how often the function should be applied (e.g. 3 to apply it every 3 cycles), the function to be applied, and the pattern you are applying it to.

For example to reverse a pattern every three cycles (and for the other two play it normally):

d1 $ every 3 rev $ n "0 1 [~ 2] 3" # sound "arpy"

Note that if the function you're applying requires additional parameters itself (such as fast 2 to make a pattern twice as fast), then you'll need to wrap it in parenthesis, like so:

d1 $ every 3 (fast 2) $ n "0 1 [~ 2] 3" # sound "arpy"

Otherwise, the every function will think it is being passed too many parameters.

See also every'.