summaryrefslogtreecommitdiff
path: root/vendor/graham-campbell/result-type
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/graham-campbell/result-type')
-rw-r--r--vendor/graham-campbell/result-type/LICENSE21
-rw-r--r--vendor/graham-campbell/result-type/composer.json33
-rw-r--r--vendor/graham-campbell/result-type/src/Error.php121
-rw-r--r--vendor/graham-campbell/result-type/src/Result.php69
-rw-r--r--vendor/graham-campbell/result-type/src/Success.php120
5 files changed, 364 insertions, 0 deletions
diff --git a/vendor/graham-campbell/result-type/LICENSE b/vendor/graham-campbell/result-type/LICENSE
new file mode 100644
index 0000000..8e7c898
--- /dev/null
+++ b/vendor/graham-campbell/result-type/LICENSE
@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) 2020-2024 Graham Campbell <hello@gjcampbell.co.uk>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
diff --git a/vendor/graham-campbell/result-type/composer.json b/vendor/graham-campbell/result-type/composer.json
new file mode 100644
index 0000000..32bfc81
--- /dev/null
+++ b/vendor/graham-campbell/result-type/composer.json
@@ -0,0 +1,33 @@
+{
+ "name": "graham-campbell/result-type",
+ "description": "An Implementation Of The Result Type",
+ "keywords": ["result", "result-type", "Result", "Result Type", "Result-Type", "Graham Campbell", "GrahamCampbell"],
+ "license": "MIT",
+ "authors": [
+ {
+ "name": "Graham Campbell",
+ "email": "hello@gjcampbell.co.uk",
+ "homepage": "https://github.com/GrahamCampbell"
+ }
+ ],
+ "require": {
+ "php": "^7.2.5 || ^8.0",
+ "phpoption/phpoption": "^1.9.3"
+ },
+ "require-dev": {
+ "phpunit/phpunit": "^8.5.39 || ^9.6.20 || ^10.5.28"
+ },
+ "autoload": {
+ "psr-4": {
+ "GrahamCampbell\\ResultType\\": "src/"
+ }
+ },
+ "autoload-dev": {
+ "psr-4": {
+ "GrahamCampbell\\Tests\\ResultType\\": "tests/"
+ }
+ },
+ "config": {
+ "preferred-install": "dist"
+ }
+}
diff --git a/vendor/graham-campbell/result-type/src/Error.php b/vendor/graham-campbell/result-type/src/Error.php
new file mode 100644
index 0000000..2c37c3e
--- /dev/null
+++ b/vendor/graham-campbell/result-type/src/Error.php
@@ -0,0 +1,121 @@
+<?php
+
+declare(strict_types=1);
+
+/*
+ * This file is part of Result Type.
+ *
+ * (c) Graham Campbell <hello@gjcampbell.co.uk>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace GrahamCampbell\ResultType;
+
+use PhpOption\None;
+use PhpOption\Some;
+
+/**
+ * @template T
+ * @template E
+ *
+ * @extends \GrahamCampbell\ResultType\Result<T,E>
+ */
+final class Error extends Result
+{
+ /**
+ * @var E
+ */
+ private $value;
+
+ /**
+ * Internal constructor for an error value.
+ *
+ * @param E $value
+ *
+ * @return void
+ */
+ private function __construct($value)
+ {
+ $this->value = $value;
+ }
+
+ /**
+ * Create a new error value.
+ *
+ * @template F
+ *
+ * @param F $value
+ *
+ * @return \GrahamCampbell\ResultType\Result<T,F>
+ */
+ public static function create($value)
+ {
+ return new self($value);
+ }
+
+ /**
+ * Get the success option value.
+ *
+ * @return \PhpOption\Option<T>
+ */
+ public function success()
+ {
+ return None::create();
+ }
+
+ /**
+ * Map over the success value.
+ *
+ * @template S
+ *
+ * @param callable(T):S $f
+ *
+ * @return \GrahamCampbell\ResultType\Result<S,E>
+ */
+ public function map(callable $f)
+ {
+ return self::create($this->value);
+ }
+
+ /**
+ * Flat map over the success value.
+ *
+ * @template S
+ * @template F
+ *
+ * @param callable(T):\GrahamCampbell\ResultType\Result<S,F> $f
+ *
+ * @return \GrahamCampbell\ResultType\Result<S,F>
+ */
+ public function flatMap(callable $f)
+ {
+ /** @var \GrahamCampbell\ResultType\Result<S,F> */
+ return self::create($this->value);
+ }
+
+ /**
+ * Get the error option value.
+ *
+ * @return \PhpOption\Option<E>
+ */
+ public function error()
+ {
+ return Some::create($this->value);
+ }
+
+ /**
+ * Map over the error value.
+ *
+ * @template F
+ *
+ * @param callable(E):F $f
+ *
+ * @return \GrahamCampbell\ResultType\Result<T,F>
+ */
+ public function mapError(callable $f)
+ {
+ return self::create($f($this->value));
+ }
+}
diff --git a/vendor/graham-campbell/result-type/src/Result.php b/vendor/graham-campbell/result-type/src/Result.php
new file mode 100644
index 0000000..8c67bcd
--- /dev/null
+++ b/vendor/graham-campbell/result-type/src/Result.php
@@ -0,0 +1,69 @@
+<?php
+
+declare(strict_types=1);
+
+/*
+ * This file is part of Result Type.
+ *
+ * (c) Graham Campbell <hello@gjcampbell.co.uk>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace GrahamCampbell\ResultType;
+
+/**
+ * @template T
+ * @template E
+ */
+abstract class Result
+{
+ /**
+ * Get the success option value.
+ *
+ * @return \PhpOption\Option<T>
+ */
+ abstract public function success();
+
+ /**
+ * Map over the success value.
+ *
+ * @template S
+ *
+ * @param callable(T):S $f
+ *
+ * @return \GrahamCampbell\ResultType\Result<S,E>
+ */
+ abstract public function map(callable $f);
+
+ /**
+ * Flat map over the success value.
+ *
+ * @template S
+ * @template F
+ *
+ * @param callable(T):\GrahamCampbell\ResultType\Result<S,F> $f
+ *
+ * @return \GrahamCampbell\ResultType\Result<S,F>
+ */
+ abstract public function flatMap(callable $f);
+
+ /**
+ * Get the error option value.
+ *
+ * @return \PhpOption\Option<E>
+ */
+ abstract public function error();
+
+ /**
+ * Map over the error value.
+ *
+ * @template F
+ *
+ * @param callable(E):F $f
+ *
+ * @return \GrahamCampbell\ResultType\Result<T,F>
+ */
+ abstract public function mapError(callable $f);
+}
diff --git a/vendor/graham-campbell/result-type/src/Success.php b/vendor/graham-campbell/result-type/src/Success.php
new file mode 100644
index 0000000..27cd85e
--- /dev/null
+++ b/vendor/graham-campbell/result-type/src/Success.php
@@ -0,0 +1,120 @@
+<?php
+
+declare(strict_types=1);
+
+/*
+ * This file is part of Result Type.
+ *
+ * (c) Graham Campbell <hello@gjcampbell.co.uk>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace GrahamCampbell\ResultType;
+
+use PhpOption\None;
+use PhpOption\Some;
+
+/**
+ * @template T
+ * @template E
+ *
+ * @extends \GrahamCampbell\ResultType\Result<T,E>
+ */
+final class Success extends Result
+{
+ /**
+ * @var T
+ */
+ private $value;
+
+ /**
+ * Internal constructor for a success value.
+ *
+ * @param T $value
+ *
+ * @return void
+ */
+ private function __construct($value)
+ {
+ $this->value = $value;
+ }
+
+ /**
+ * Create a new error value.
+ *
+ * @template S
+ *
+ * @param S $value
+ *
+ * @return \GrahamCampbell\ResultType\Result<S,E>
+ */
+ public static function create($value)
+ {
+ return new self($value);
+ }
+
+ /**
+ * Get the success option value.
+ *
+ * @return \PhpOption\Option<T>
+ */
+ public function success()
+ {
+ return Some::create($this->value);
+ }
+
+ /**
+ * Map over the success value.
+ *
+ * @template S
+ *
+ * @param callable(T):S $f
+ *
+ * @return \GrahamCampbell\ResultType\Result<S,E>
+ */
+ public function map(callable $f)
+ {
+ return self::create($f($this->value));
+ }
+
+ /**
+ * Flat map over the success value.
+ *
+ * @template S
+ * @template F
+ *
+ * @param callable(T):\GrahamCampbell\ResultType\Result<S,F> $f
+ *
+ * @return \GrahamCampbell\ResultType\Result<S,F>
+ */
+ public function flatMap(callable $f)
+ {
+ return $f($this->value);
+ }
+
+ /**
+ * Get the error option value.
+ *
+ * @return \PhpOption\Option<E>
+ */
+ public function error()
+ {
+ return None::create();
+ }
+
+ /**
+ * Map over the error value.
+ *
+ * @template F
+ *
+ * @param callable(E):F $f
+ *
+ * @return \GrahamCampbell\ResultType\Result<T,F>
+ */
+ public function mapError(callable $f)
+ {
+ return self::create($this->value);
+ }
+}