.. index:: single: either
.. _either/0:

.. rst-class:: right

**object**

``either``
==========

Types and predicates for extended type-checking and handling of expected terms.

| **Availability:** 
|    ``logtalk_load(expecteds(loader))``

| **Author:** Paulo Moura
| **Version:** 0:9:0
| **Date:** 2025-06-19

| **Compilation flags:**
|    ``static, context_switching_calls``


| **Provides:**
|    :ref:`type::type/1 <type/0::type/1>`
|    :ref:`type::check/2 <type/0::check/2>`
|    :ref:`arbitrary::arbitrary/1 <arbitrary/0::arbitrary/1>`
|    :ref:`arbitrary::arbitrary/2 <arbitrary/0::arbitrary/2>`
|    :ref:`arbitrary::shrinker/1 <arbitrary/0::shrinker/1>`
|    :ref:`arbitrary::shrink/3 <arbitrary/0::shrink/3>`
|    :ref:`arbitrary::edge_case/2 <arbitrary/0::edge_case/2>`
| **Uses:**
|    :ref:`expected <expected/0>`
|    :ref:`expected(Expected) <expected/1>`
|    :ref:`random <random/0>`
|    :ref:`type <type/0>`

| **Remarks:**

   - Type-checking support: Defines a ``either(ValueType, ErrorType)`` type for checking expected terms where the value and error terms must be of the given types.
   - QuickCheck support: Defines clauses for the ``type::arbitrary/1-2``, ``arbitrary::shrinker/1``, ``arbitrary::shrink/3``, and ``arbitrary::edge_case/2`` predicates to allow generating random values for the ``either(ValueType, ErrorType)`` type.

| **Inherited public predicates:**
|    (none)

.. contents::
   :local:
   :backlinks: top

Public predicates
-----------------

.. index:: expecteds/2
.. _either/0::expecteds/2:

``expecteds/2``
^^^^^^^^^^^^^^^

Returns the values stored in the expected terms that hold a value.

| **Compilation flags:**
|    ``static``

| **Template:**
|    ``expecteds(Expecteds,Values)``
| **Mode and number of proofs:**
|    ``expecteds(+list(expected),-list)`` - ``one``


------------

.. index:: unexpecteds/2
.. _either/0::unexpecteds/2:

``unexpecteds/2``
^^^^^^^^^^^^^^^^^

Returns the errors stored in the expected terms that hold an error.

| **Compilation flags:**
|    ``static``

| **Template:**
|    ``unexpecteds(Expecteds,Errors)``
| **Mode and number of proofs:**
|    ``unexpecteds(+list(expected),-list)`` - ``one``


------------

.. index:: partition/3
.. _either/0::partition/3:

``partition/3``
^^^^^^^^^^^^^^^

Retrieves and partitions the values and errors hold by the expected terms.

| **Compilation flags:**
|    ``static``

| **Template:**
|    ``partition(Expecteds,Values,Errors)``
| **Mode and number of proofs:**
|    ``partition(+list(expected),-list,-list)`` - ``one``


------------

.. index:: sequence/2
.. _either/0::sequence/2:

``sequence/2``
^^^^^^^^^^^^^^

Returns an expected term with a list of all values when all expected terms hold values. Otherwise returns the first expected term holding an error.

| **Compilation flags:**
|    ``static``

| **Template:**
|    ``sequence(Expecteds,Expected)``
| **Mode and number of proofs:**
|    ``sequence(+list(expected),--nonvar)`` - ``one``


------------

.. index:: traverse/3
.. _either/0::traverse/3:

``traverse/3``
^^^^^^^^^^^^^^

Applies a closure to each list element to generate expected terms and then sequences them into a single expected term holding all values or the first error.

| **Compilation flags:**
|    ``static``

| **Template:**
|    ``traverse(Closure,Terms,Expected)``
| **Meta-predicate template:**
|    ``traverse(2,*,*)``
| **Mode and number of proofs:**
|    ``traverse(+callable,+list,--nonvar)`` - ``one``


------------

Protected predicates
--------------------

(no local declarations; see entity ancestors if any)

Private predicates
------------------

(no local declarations; see entity ancestors if any)

Operators
---------

(none)

.. seealso::

   :ref:`expected <expected/0>`, :ref:`expected(Expected) <expected/1>`, :ref:`type <type/0>`, :ref:`arbitrary <arbitrary/0>`

