Skip to content

Instantly share code, notes, and snippets.

@azjezz
Last active May 27, 2021 12:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save azjezz/b50c809e2aba2c570b3e36fde6b8dd81 to your computer and use it in GitHub Desktop.
Save azjezz/b50c809e2aba2c570b3e36fde6b8dd81 to your computer and use it in GitHub Desktop.
<?php
/**
* @context={}
*/
function foo(): void {}
/**
* @context={io}
*/
function bar(): void { echo 'bar'; }
/**
* @context={rand}
*/
function baz(): int { return mt_rand(1, 10); }
/**
* @context={io, rand}
*/
function qux(): void { echo baz(); }
/**
* @template Tk of array-key
* @template Tv
* @template Ts
*
* @context-template C1
* @context-template C2
*
* @param (iterable<Tk, Tv>){C1} $iterable
* @param (callable(Tk): Ts){C2} $fun
*
* @return array<Tk, Ts>
*
* @context={...C1, ...C2}
*/
function map(iterable $iterable, callable $fun): array
{
$r = [];
foreach($iterable as $k => $i) { $r[$k] = $i; }
return $r;
}
/**
* this function is pure, so it has no effects ( {} )
*
* @context={}
*/
function main(): void
{
map(
[1, 2],
/**
* @context={}
*/
static fn(int $i): int => $i + 1
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment