.. index:: pairs
.. _pairs/0:

.. rst-class:: right

**object**

``pairs``
=========

Useful predicates over lists of pairs (key-value terms).

| **Author:** Paulo Moura
| **Version:** 1:5:0
| **Date:** 2019-03-08

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


| **Dependencies:**
|   (none)


| **Remarks:**

   - Usage: This object can be loaded independently of other entities in the ``types`` library by using the goal ``logtalk_load(types(pairs))``.

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

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

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

.. raw:: html

   <div id="keys_values/3"> </div>

.. index:: keys_values/3
.. _pairs/0::keys_values/3:

``keys_values/3``
^^^^^^^^^^^^^^^^^

Converts between a list of pairs and lists of keys and values.

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

| **Template:**
|    ``keys_values(Pairs,Keys,Values)``
| **Mode and number of proofs:**
|    ``keys_values(+list(pair),-list,-list)`` - ``one``
|    ``keys_values(-list(pair),+list,+list)`` - ``one``


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

.. raw:: html

   <div id="keys/2"> </div>

.. index:: keys/2
.. _pairs/0::keys/2:

``keys/2``
^^^^^^^^^^

Extracts a list of keys from a list of pairs.

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

| **Template:**
|    ``keys(Pairs,Keys)``
| **Mode and number of proofs:**
|    ``keys(+list(pair),-list)`` - ``one``


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

.. raw:: html

   <div id="values/2"> </div>

.. index:: values/2
.. _pairs/0::values/2:

``values/2``
^^^^^^^^^^^^

Extracts a list of values from a list of pairs.

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

| **Template:**
|    ``values(Pairs,Values)``
| **Mode and number of proofs:**
|    ``values(+list(pair),-list)`` - ``one``


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

.. raw:: html

   <div id="transpose/2"> </div>

.. index:: transpose/2
.. _pairs/0::transpose/2:

``transpose/2``
^^^^^^^^^^^^^^^

Transposes a list of pairs by swapping each pair key and value. The relative order of the list elements is kept.

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

| **Template:**
|    ``transpose(Pairs,TransposedPairs)``
| **Mode and number of proofs:**
|    ``transpose(+list(pair),-list(pair))`` - ``one``


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

.. raw:: html

   <div id="group_by_key/2"> </div>

.. index:: group_by_key/2
.. _pairs/0::group_by_key/2:

``group_by_key/2``
^^^^^^^^^^^^^^^^^^

Groups pairs by key by constructing new pairs by grouping all values for a given key in a list. Keys are compared using equality. The relative order of the values for the same key is kept. The resulting list of pairs is sorted by key.

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

| **Template:**
|    ``group_by_key(Pairs,Groups)``
| **Mode and number of proofs:**
|    ``group_by_key(+list(pair),-list(pair))`` - ``one``


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

.. raw:: html

   <div id="map/3"> </div>

.. index:: map/3
.. _pairs/0::map/3:

``map/3``
^^^^^^^^^

Maps a list into pairs using a closure that applies to each list element to compute its key.

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

| **Template:**
|    ``map(Closure,List,Pairs)``
| **Meta-predicate template:**
|    ``map(2,*,*)``
| **Mode and number of proofs:**
|    ``map(@callable,+list,-list(pair))`` - ``one``


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

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

(none)

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

(none)

Operators
---------

(none)

