Jump to content

Function composition: Difference between revisions

m (syntax hghlighting fixup automation)
Line 2,945:
{*}$sin_asin 0.5 ;# ==> 0.5
{*}[compose abs int] -3.14 ;# ==> 3</syntaxhighlight>
 
=={{header|Transd}}==
<syntaxhighlight lang="Scheme">#lang transd
 
MainModule: {
// Make a short alias for a function type that takes a string and
// returns a string. Call it 'Shader'.
 
Shader: typealias(Lambda<String String>),
 
// 'composer' function takes two Shaders, combines them into
// a single Shader, which is a capturing closure, аnd returns
// this closure to the caller.
// [[f1,f2]] is a list of captured variables
 
composer: (λ f1 Shader() f2 Shader()
(ret Shader(λ[[f1,f2]] s String() (exec f1 (exec f2 s))))),
 
_start: (λ
// create a combined shader as a local variable 'render'
 
locals: render (composer
Shader(λ s String() (ret (toupper s)))
Shader(λ s String() (ret (+ s "!"))))
// call this combined shader as a usual shader with passing
// a string to it, аnd receiving from it the combined result of
// its two captured shaders
 
(textout (exec render "hello")))
}</syntaxhighlight>
{{out}}
<pre>
HELLO!
</pre>
 
=={{header|TypeScript}}==
111

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.