This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
namespace Lens; | |
use Closure; | |
class Lens | |
{ | |
/** @var Closure */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
namespace RFSM3; | |
use Pwm\SFlow\FSM; | |
use Pwm\SFlow\Transition; | |
require_once __DIR__ . '/../vendor/autoload.php'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
final class Compose | |
{ | |
public static function these(Closure ...$closures): Closure | |
{ | |
return array_reduce($closures, function (Closure $composed, Closure $f): Closure { | |
return function ($x) use ($f, $composed) { | |
return $f($composed($x)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
interface Subject { | |
public function attach(Observer $observer): void; | |
} | |
interface Observer { | |
public function reactTo(string $event): void; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# OPTIONS_GHC -Wall #-} | |
-- An example of representing a connection | |
-- Types | |
data ConnInfo = ConnInfo | |
{ connState :: ConnState | |
, server :: String | |
} deriving (Show) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
function mapToList(array $map): array | |
{ | |
$list = []; | |
foreach ($map as $k => $v) { | |
$list[] = \is_array($v) | |
? [$k, mapToList($v)] | |
: [$k, $v]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
use Pwm\UuidV4\UuidV4; | |
use Doctrine\DBAL\Platforms\AbstractPlatform; | |
use Doctrine\DBAL\Types\ConversionException; | |
use Doctrine\DBAL\Types\Type; | |
final class UuidV4Type extends Type | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* The timezone in these datetimes look the same but they are in fact represent different UTC offsets. | |
* The 1st one maps to UTC+01 (BST) while the 2nd one maps to a UTC+00 (GMT). | |
* This is because daylight saving time (DST) aka. clocks going forward/backward happen on different days in different years. | |
*/ | |
$now = new DateTime('2018-03-26T08:00:00', new DateTimeZone('Europe/London')); | |
$inAYear = new DateTime('2019-03-26T08:00:00', new DateTimeZone('Europe/London')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
function Node($node, array $subtree = []): array { | |
return [ | |
'node' => $node, | |
'subtree' => $subtree | |
]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
// https://softwareengineering.stackexchange.com/questions/334305/how-to-model-a-circular-reference-between-immutable-objects-in-c | |
final class Department { | |
/** @var string */ | |
private $name; | |
/** @var Closure|User */ | |
private $user; |