CKTIS / PHP
Sestavljanje funkcij
Pri sestavljanju posredujte celoten rezultat prve funkcije kot argument druge.
Različica: PHP 8.4; repository runtime, production runtime not attested
Sintaksa
fn($x) => $after($before($x));Pri sestavljanju posredujte celoten rezultat prve funkcije kot argument druge. Vrstni red lahko spremeni rezultat tudi pri čistih funkcijah. Tip rezultata mora ustrezati parametru. Zgodnja izjema prepreči poznejše klice.
function then(callable $first,callable $next):Closure{return fn(int $x)=>$next($first($x));}
$add=fn(int $v)=>$v+2;$double=fn(int $v)=>2*$v;echo json_encode([then($add,$double)(3),then($double,$add)(3)]);
[10,8]
Primeri
<?php
function then(callable $first,callable $next):Closure{return fn(int $x)=>$next($first($x));}
$add=fn(int $v)=>$v+2;$double=fn(int $v)=>2*$v;echo json_encode([then($add,$double)(3),then($double,$add)(3)]);
Rezultat
[10,8]