*/ class struct_pod { /** * @var bool */ public $full; /** * @var null|TypeValue */ public $value; /** * @param bool $full * @param null|TypeValue $value */ public function __construct( bool $full, $value ) { $this->full = $full; $this->value = $value; } } /** * @template TypeValue * @return struct_pod * @author Christian Fraß */ function make_toom( ) : struct_pod { return (new struct_pod(false, null)); } /** * @template TypeValue * @param TypeValue $value * @return struct_pod * @author Christian Fraß */ function make_full( $value ) : struct_pod { return (new struct_pod(true, $value)); } /** * @template TypeValue * @param struct_pod * @return bool * @author Christian Fraß */ function has( struct_pod $pod ): bool { return $pod->full; } /** * @template TypeValue * @param struct_pod * @return TypeValue * @author Christian Fraß */ function get( struct_pod $pod ) { if (! $pod->full) { throw (new \Exception('empty')); } else { return $pod->value; } } /** * creates a pod on base of the input pod; i.e. if the input pod is empty, the output put is too; if the input pod is * full, the function is applied to its value to make up a new full pod with the result value * * @template TypeValueFrom * @template TypeValueTo * @param struct_pod * @param \Closure {function} * @return struct_pod * @author Christian Fraß */ function brook( struct_pod $pod, \Closure $function ) : struct_pod { if (! is_something($pod)) { return make_empty(); } else { return make_full($function($pod->value)); } } ?>