HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux wordpress-ubuntu-s-2vcpu-4gb-fra1-01 5.4.0-169-generic #187-Ubuntu SMP Thu Nov 23 14:52:28 UTC 2023 x86_64
User: root (0)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/zaklada/wp-content/plugins/sitepress-multilingual-cms/vendor/wpml/fp/core/Either.php
<?php

namespace WPML\FP;

use Exception;
use WPML\Collect\Support\Traits\Macroable;
use WPML\FP\Functor\Functor;
use WPML\FP\Functor\Pointed;

/**
 * Class Either
 * @package WPML\FP
 *
 * @method static callable|Right of( ...$value ) - Curried :: a → Right a
 *
 * @method static callable|Left left( ...$value ) - Curried :: a → Left a
 *
 * @method static callable|Right right( ...$value ) - Curried :: a → Right a
 *
 * @method static callable|Either fromNullable( ...$value ) - Curried :: a → Either a
 */
abstract class Either {
	use Functor;
	use Macroable;

	public static function init() {
		self::macro( 'of', Right::of() );

		self::macro( 'left', Left::of() );

		self::macro( 'right', Right::of() );

		self::macro( 'fromNullable', curryN( 1, function ( $value ) {
			return is_null( $value ) ? self::left( $value ) : self::right( $value );
		} ) );
	}

	public function join() {
		if( ! $this->value instanceof Either ) {
			return $this;
		}
		return $this->value->join();
	}

	abstract public function chain( callable $fn );
	abstract public function orElse( callable $fn );
}

class Left extends Either {

	use ConstApplicative;
	use Pointed;

	public function map( callable $fn ) {
		return $this; // noop
	}

	public function get() {
		throw new Exception( "Can't extract the value of Left" );
	}

	/**
	 * @param mixed $other
	 *
	 * @return mixed
	 */
	public function getOrElse( $other ) {
		return $other;
	}

	public function orElse( callable $fn ) {
		return Either::right( $fn( $this->value ) );
	}

	public function chain( callable $fn ) {
		return $this;
	}

	public function getOrElseThrow( $value ) {
		throw new Exception( $value );
	}

	public function filter( $fn ) {
		return $this;
	}

	public function tryCatch( callable $fn ) {
		return $this; // noop
	}

}

class Right extends Either {

	use Applicative;
	use Pointed;

	public function map( callable $fn ) {
		return Either::of( $fn( $this->value ) );
	}

	public function getOrElse( $other ) {
		return $this->value;
	}

	public function orElse( callable $fn ) {
		return $this;
	}

	public function getOrElseThrow( $value ) {
		return $this->value;
	}

	public function chain( callable $fn ) {
		return $this->map($fn)->join();
	}

	public function filter( callable $fn ) {
		return Either::fromNullable( $fn( $this->value ) ? $this->value : null );
	}

	public function tryCatch( callable $fn ) {
		return tryCatch( function() use ( $fn ) { return $fn( $this->value ); } );
	}

}

Either::init();