


This file contains hidden or 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
def path(dct: dict, paths: list): | |
k = paths[0] | |
v = dct.get(k, None) | |
return v if type(v) is not dict else path(v, paths[1:]) | |
# or | |
def path(dct: dict, paths: list): | |
k = paths[0] |
This file contains hidden or 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
type(1) // => int | |
type(1.1) // => float | |
type('hello') // => string | |
type([1, 2, 3, 4]) // => array | |
type({true: 1, false: 0}) // => hashmap | |
type(?) // => null | |
// class | |
User { | |
str name, [str, ?] lastname |
This file contains hidden or 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 | |
abstract class Container extends \Xtreamwayz\Pimple\Container | |
{ | |
public function __construct(array $values = []) | |
{ | |
parent::__construct($values)); | |
$this->initializeProviders(); | |
} |
This file contains hidden or 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 | |
// [a] -> a | |
function head(array $list) | |
{ | |
return array_slice($list, 0, 1)[0]; | |
} | |
// [a] -> a | |
function last(array $list) |
This file contains hidden or 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 id($x) | |
{ | |
return $x; | |
} | |
function anyPass(array $preds) |
This file contains hidden or 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 | |
function head($str) | |
{ | |
return substr($str, 0, 1); | |
} | |
function last($str) | |
{ | |
return substr($str, -1); |
This file contains hidden or 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 | |
use const Prelude\{_, id, isResource}; | |
use function Prelude\{always, ifElse, apply, placeholder}; | |
class Stream | |
{ | |
protected $stream; | |
public function __construct($stream, $options = []) |