Download the PHP package hoa/option without Composer

On this page you can find all versions of the php package hoa/option. 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 option

Hoa


Build status Code coverage Packagist License

Hoa is a modular, extensible and structured set of PHP libraries.
Moreover, Hoa aims at being a bridge between industrial and research worlds.

Hoa\Option

Help on IRC Help on Gitter Documentation Board

This library is an implementation of the famous Option polymorphic type (also called Maybe). An Option represents an optional value, either there is Some value, or there is None which is the equivalent of null. This is a convenient and safe way to manipulate an optional value.

Learn more.

Installation

With Composer, to include this library into your dependencies, you need to require hoa/option:

For more installation procedures, please read the Source page.

Testing

Before running the test suites, the development dependencies must be installed:

Then, to run all the test suites:

For more information, please read the contributor guide.

Quick usage

The following examples illustrate how to use the Hoa\Option\Option class.

Build an optional value

There are two static methods to allocate an optional value:

Two functional aliases exist, respectively:

In the next examples, it is assumed that use function Hoa\Option\{Some, None} is declared, so that we can use Some and None directly.

Basic operations

The isSome and isNone methods respectively return true if the option contains some value or none:

The unwrap method returns the contained value if there is some, or throws a RuntimeException if there is none:

In general, because of the unexpected exception, its use is discouraged. Prefer to use either: expect, unwrapOr, isSome, or isNone for instance.

One common mistake is to think that it is required to extract/unwrap the value from the option. Actually, the Hoa\Option\Option API is designed to always manipulate an option without having the need to extract its contained value. New options can be constructed or mapped, see next sections.

The unwrap method can throw a RuntimeException with a default message. To have a custom message, please use the expect method:

The unwrapOr method returns the contained value if there is some, or a default value if none:

The unwrapOrElse method returns the contained value if there is some, or computes a default value from the given callable if none:

Mappers

Mappers transform an option into another option by applying a callable to the contained value if some.

The mapOr mapper transform an option into another option but use a default value if there is no contained value:

The result of mapOr is always an option with some value.

The mapOrElse mapper is similar to mapOr but computes the default value from a callable:

Boolean operations

It is possible to apply boolean operations on options. The and method returns a none option if the current option has no value, otherwise it returns the right option:

The andThen method returns a none option if the current option has no value, otherwise it returns a new option computed by a callable. Some languages call this operation flatmap.

The or method returns the current option if it has some value, otherwise it returns the right option:

Finally the orElse option returns the option if it has some value, otherwise it returns a new option computed by a callable:

Documentation

The hack book of Hoa\Option contains detailed information about how to use this library and how it works.

To generate the documentation locally, execute the following commands:

More documentation can be found on the project's website: hoa-project.net.

Getting help

There are mainly two ways to get help:

Contribution

Do you want to contribute? Thanks! A detailed contributor guide explains everything you need to know.

License

Hoa is under the New BSD License (BSD-3-Clause). Please, see LICENSE for details.


All versions of option with dependencies

PHP Build Version
Package Version
Requires php Version >=7.1
hoa/consistency Version ~2.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 hoa/option contains the following files

Loading the files please wait ....