Download the PHP package ascetik/hypothetik without Composer

On this page you can find all versions of the php package ascetik/hypothetik. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package hypothetik

Hypothetik

[EN]

Home made OOP "Monad", for an easier management of hypothetical values.

Release notes

Version 0.3.0 : still a draft version.

Php version : 8.2.14

Descriptions

Interfaces

OptionnalValue is a general interface shared by both Hypothetik an Option instances.


The Hypothetik interface describes the way to handle a value which may be null or false using callables.


The Option interface describes the behavior of an instance containing the exepcted value :

This package includes 2 Option implementations : final class None and final class Some. Anyone can build another implementation of Option to replace Some class. That's why this interface is exposed here.

An Option is a simple ValueObject with simple behaviors, unuseful outside of an Hypothetik instance.

Available Implementations

final class Maybe : The Maybe class is the main tool of this package. It handles an Option which may contain a value, or may not, and drives different operations on this value, or not...

Maybe contructor is private. See examples below for instanciation.


final class When : (v.0.3.0) This implementation works almost like Maybe. The difference is that When contains an Option with a bool value and a falsy Option is considered as invalid.

Private constructor. Use When::ever(bool) or Maybe::some(bool) methods to build an instance.


final class Either :

The Either class handles a function to execute according to a Maybe Option value.

An Either instance is exposed by a Hypothetik implementation for usage, unuseful in any other context.


final class None is a "null value" Option. final class Some is a not null value Option.

Usage

Construction

As Maybe constructor access is not available, 3 factory methods are provided :

Valid value : mixed value not null

To retrieve raw optionnal value from the "$some" Maybe instance of previous example :

Pass an optionnal value through a function an get the result :

The Option value is always passed to the function as first parameter.

It is possible to add arguments, separated by comas. The order of the arguments is important.

Another example with some added arguments :

It is possible to get a new Hypothetik instance containing the result of a function. Once again, the Option value is always passed to the function as first parameter and arguments can be added :

As a new Maybe instance is returned, we can chain calls of this method :

Invalid value : null value

With a null value, things are slightly different. Both apply() and value() methods will return null again. The then() method returns a Maybe with a null Option value.

Take a look at the "$not" instance from the first example :

Maybe provides a way to substitute an "invalid" instance to a valid one by using otherwise method :

Some other examples chaining methods :

The otherwise method is only applied when the value is null. So :

Of course, we already know the content of the instances of the examples above. During runtime, we just can suppose that our value could be null. Sometimes, then() and otherwise() are not enough to make the job we want to. Another possibility is to use either() :

And to retrieve a new Hypothetik instance from Either :

Boolean value :

An hypothetik boolean value works a different way. It always holds an Option with a boolean value where false is the invalid one. The Hypothetik interface ensures a fully substitutionnable instance, providing the hability to chain methods from a Maybe to a When or reverse.

Here's a simple example :

When class has its own static factory method :

Methods apply() and then won't use the boolean value as first function parameter, this time. Additionnal rguments are allowed, separated by comas, just like Maybe.

Combining Maybe and When instance calls :

Notes

No dependency injection. User has to provide required instances if needed. A Maybe cannot carry another Hypothetik, an Option cannot carry another Option. Trying to do so will return the given instance as is.

Issues

I'm still not able to use Php Documentation properly in order to provide autocompletion from any IDE. Problems on generic types handling.

I still don't need any Hypothetik container to handle multiple Hypothetik instances. I'll think about this kind of implementation only if necessary...

Maybe some tests are still missing. I'm not sure to cover all possible use cases.


All versions of hypothetik with dependencies

PHP Build Version
Package Version
Requires ascetik/callapsule Version ^0.4.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package ascetik/hypothetik contains the following files

Loading the files please wait ....