

BiMap — BiMap v1.2.2

 try {

 var settings = JSON.parse(localStorage.getItem('ex\_doc:settings') || '{}');

 if (settings.theme === 'dark' ||

 ((settings.theme === 'system' || settings.theme == null) &&

 window.matchMedia('(prefers-color-scheme: dark)').matches)

 ) {

 document.body.classList.add('dark')

 }

 } catch (error) { }

 

Settings

[View Source](https://github.com/mkaput/elixir-bimap/blob/v1.2.2/README.md#L1 "View Source")

BiMap

===============================================================================================================

[![Build Status](https://github.com/mkaput/elixir-bimap/workflows/CI/badge.svg)](https://github.com/mkaput/elixir-bimap/actions?query=workflow%3ACI)

[![Version](https://img.shields.io/hexpm/v/bimap.svg)](https://hex.pm/packages/bimap)

[![Hex Docs](https://img.shields.io/badge/hex-docs-lightgreen.svg)](https://hexdocs.pm/bimap/)

[![Download](https://img.shields.io/hexpm/dt/bimap.svg)](https://hex.pm/packages/bimap)

[![License](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)

[![Last Updated](https://img.shields.io/github/last-commit/mkaput/elixir-bimap.svg)](https://github.com/mkaput/elixir-bimap/commits/master)

Elixir implementation of bidirectional map ([`BiMap`](BiMap.html)) and multimap ([`BiMultiMap`](BiMultiMap.html)).

[installation](#installation)

 Installation

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

The package can be installed by adding `bimap` to your list of dependencies in `mix.exs`:

```

def deps do

 [{:bimap, "~> 1.2"}]

end

```

[getting-started](#getting-started)

 Getting started

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

For more examples, checkout [`BiMap`](https://hexdocs.pm/bimap/BiMap.html) and [`BiMultiMap`](https://hexdocs.pm/bimap/BiMultiMap.html) on hex docs.

### 

[bimap](#bimap)

 BiMap

```

iex(1)> Mix.install [:bimap]

iex(2)> bm = BiMap.new(a: 1, b: 2)

#BiMap<[a: 1, b: 2]>

iex(3)> BiMap.get(bm, :a)

1

iex(4)> BiMap.get\_key(bm, 2)

:b

iex(5)> BiMap.put(bm, :a, 3)

#BiMap<[a: 3, b: 2]>

iex(6)> BiMap.put(bm, :c, 2)

#BiMap<[a: 1, c: 2]>

```

### 

[bimultimap](#bimultimap)

 BiMultiMap

```

iex(1)> Mix.install [:bimap]

iex(2)> mm = BiMultiMap.new(a: 1, b: 2, b: 1)

#BiMultiMap<[a: 1, b: 1, b: 2]>

iex(3)> BiMultiMap.get(mm, :a)

[1]

iex(4)> BiMultiMap.get\_keys(mm, 1)

[:a, :b]

iex(5)> BiMultiMap.put(mm, :a, 3)

#BiMultiMap<[a: 1, a: 3, b: 1, b: 2]>

```

[changelog](#changelog)

 Changelog

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

All notable changes to this project are documented on the [GitHub releases](https://github.com/mkaput/elixir-bimap/releases) page.

[license](#license)

 License

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

See the [LICENSE](https://github.com/mkaput/elixir-bimap/blob/master/LICENSE.txt) file for license rights and limitations (MIT).

[← Previous Page

 

API Reference](api-reference.html)





BiMap — BiMap v1.2.2

 try {

 var settings = JSON.parse(localStorage.getItem('ex\_doc:settings') || '{}');

 if (settings.theme === 'dark' ||

 ((settings.theme === 'system' || settings.theme == null) &&

 window.matchMedia('(prefers-color-scheme: dark)').matches)

 ) {

 document.body.classList.add('dark')

 }

 } catch (error) { }

 

Settings

[View Source](https://github.com/mkaput/elixir-bimap/blob/v1.2.2/lib/bimap.ex#L1 "View Source")

BiMap

(BiMap v1.2.2)

=================================================================================================================================

Bi-directional map implementation backed by two maps.

> In computer science, a bidirectional map, or hash bag, is an associative data

> structure in which the `(key, value)` pairs form a one-to-one correspondence.

> Thus the binary relation is functional in each direction: `value` can also

> act as a key to `key`. A pair `(a, b)` thus provides a unique coupling

> between a `a` and `b` so that `b` can be found when `a` is used as a key and

> `a` can be found when `b` is used as a key.

> 

> ~[Wikipedia](https://en.wikipedia.org/wiki/Bidirectional_map)

> 

> 

Entries in bimap do not follow any order.

BiMaps do not impose any restriction on the key and value type: anything can be

a key in a bimap, and also anything can be a value. As a bidirectional

key-value structure, bimaps do not allow duplicated keys and values. This means

it is not possible to store `[(A, B), (A, C)]` or `[(X, Z), (Y, Z)]` in

the bimap. If you need to lift this restriction to only not allowing duplicated

key-value pairs, check out [`BiMultiMap`](BiMultiMap.html).

Keys and values are compared using the exact-equality operator (`===`).

[example](#module-example)

 Example

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

```

iex> bm = BiMap.new(a: 1, b: 2)

#BiMap<[a: 1, b: 2]>

iex> BiMap.get(bm, :a)

1

iex> BiMap.get\_key(bm, 2)

:b

iex> BiMap.put(bm, :a, 3)

#BiMap<[a: 3, b: 2]>

iex> BiMap.put(bm, :c, 2)

#BiMap<[a: 1, c: 2]>

```

[protocols](#module-protocols)

 Protocols

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

[`BiMap`](BiMap.html#content) implements [`Enumerable`](https://hexdocs.pm/elixir/Enumerable.html), [`Collectable`](https://hexdocs.pm/elixir/Collectable.html) and [`Inspect`](https://hexdocs.pm/elixir/Inspect.html) protocols.

[Link to this section](#summary)

 Summary

==========================================

[Types](#types)

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

[k()](#t:k/0)

Key type

[t()](#t:t/0)

[t(k, v)](#t:t/2)

[v()](#t:v/0)

Value type

[Functions](#functions)

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

[delete(bimap, kv)](#delete/2)

Convenience shortcut for [`delete/3`](#delete/3).

[delete(bimap, key, value)](#delete/3)

Deletes `{key, value}` pair from `bimap`.

[delete\_key(bimap, key)](#delete_key/2)

Deletes `{key, _}` pair from `bimap`.

[delete\_value(bimap, value)](#delete_value/2)

Deletes `{_, value}` pair from `bimap`.

[equal?(bimap1, bimap2)](#equal?/2)

Checks if two bimaps are equal.

[fetch!(bimap, key)](#fetch!/2)

Fetches the value for specific `key` in `bimap`.

[fetch(bimap, key)](#fetch/2)

Fetches the value for specific `key` in `bimap`

[fetch\_key!(bimap, value)](#fetch_key!/2)

Fetches the key for specific `value` in `bimap`.

[fetch\_key(bimap, value)](#fetch_key/2)

Fetches the key for specific `value` in `bimap`

[get(bimap, key, default \\ nil)](#get/3)

Gets the value for specific `key` in `bimap`

[get\_key(bimap, value, default \\ nil)](#get_key/3)

Gets the key for specific `value` in `bimap`

[has\_key?(bimap, key)](#has_key?/2)

Checks if `bimap` contains `key`.

[has\_value?(bimap, value)](#has_value?/2)

Checks if `bimap` contains `value`.

[keys(bimap)](#keys/1)

Returns all keys from `bimap`.

[left(bimap)](#left/1)

Returns `key ➜ value` mapping of `bimap`.

[member?(bimap, kv)](#member?/2)

Convenience shortcut for [`member?/3`](#member?/3).

[member?(bimap, key, value)](#member?/3)

Checks if `bimap` contains `{key, value}` pair.

[new()](#new/0)

Creates a new bimap.

[new(enumerable)](#new/1)

Creates a bimap from `enumerable` of key-value pairs.

[new(enumerable, transform)](#new/2)

Creates a bimap from `enumerable` via transform function returning key-value

pairs.

[put(bimap, kv)](#put/2)

Convenience shortcut for [`put/3`](#put/3)

[put(bimap, key, value)](#put/3)

Inserts `{key, value}` pair into `bimap`.

[put\_new\_key(bimap, key, value)](#put_new_key/3)

Inserts `{key, value}` pair into `bimap` if `key` is not already in `bimap`.

[put\_new\_value(bimap, key, value)](#put_new_value/3)

Inserts `{key, value}` pair into `bimap` if `value` is not already in `bimap`.

[right(bimap)](#right/1)

Returns `value ➜ key` mapping of `bimap`.

[size(bimap)](#size/1)

Returns the number of elements in `bimap`.

[to\_list(bimap)](#to_list/1)

Returns list of unique key-value pairs in `bimap`.

[values(bimap)](#values/1)

Returns all values from `bimap`.

[Link to this section](#types)

Types

=====================================

[Link to this type](#t:k/0 "Link to this type")

k()

===

[View Source](https://github.com/mkaput/elixir-bimap/blob/v1.2.2/lib/bimap.ex#L44 "View Source")

```

@type k() :: [term](https://hexdocs.pm/elixir/typespecs.html#built-in-types)()

```

Key type

[Link to this type](#t:t/0 "Link to this type")

t()

===

[View Source](https://github.com/mkaput/elixir-bimap/blob/v1.2.2/lib/bimap.ex#L60 "View Source")

```

@type t() :: [t](#t:t/2)([term](https://hexdocs.pm/elixir/typespecs.html#built-in-types)(), [term](https://hexdocs.pm/elixir/typespecs.html#built-in-types)())

```

[Link to this type](#t:t/2 "Link to this type")

t(k, v)

=======

[View Source](https://github.com/mkaput/elixir-bimap/blob/v1.2.2/lib/bimap.ex#L55 "View Source")

```

@type t(k, v) :: %BiMap{keys: internal_keys(k, v), values: internal_values(k, v)}

```

[Link to this type](#t:v/0 "Link to this type")

v()

===

[View Source](https://github.com/mkaput/elixir-bimap/blob/v1.2.2/lib/bimap.ex#L47 "View Source")

```

@type v() :: [term](https://hexdocs.pm/elixir/typespecs.html#built-in-types)()

```

Value type

[Link to this section](#functions)

Functions

=============================================

[Link to this function](#delete/2 "Link to this function")

delete(bimap, kv)

=================

[View Source](https://github.com/mkaput/elixir-bimap/blob/v1.2.2/lib/bimap.ex#L572 "View Source")

```

@spec delete(

  [t](#t:t/0)(),

  {[k](#t:k/0)(), [v](#t:v/0)()}

) :: [t](#t:t/0)()

```

Convenience shortcut for [`delete/3`](#delete/3).

[Link to this function](#delete/3 "Link to this function")

delete(bimap, key, value)

=========================

[View Source](https://github.com/mkaput/elixir-bimap/blob/v1.2.2/lib/bimap.ex#L510 "View Source")

```

@spec delete([t](#t:t/0)(), [k](#t:k/0)(), [v](#t:v/0)()) :: [t](#t:t/0)()

```

Deletes `{key, value}` pair from `bimap`.

If the `key` does not exist, or `value` does not match, returns `bimap`

unchanged.

[examples](#delete/3-examples)

 Examples

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

```

iex> bimap = BiMap.new([a: 1, b: 2])

iex> BiMap.delete(bimap, :b, 2)

#BiMap<[a: 1]>

iex> BiMap.delete(bimap, :c, 3)

#BiMap<[a: 1, b: 2]>

iex> BiMap.delete(bimap, :b, 3)

#BiMap<[a: 1, b: 2]>

```

[Link to this function](#delete_key/2 "Link to this function")

delete\_key(bimap, key)

=======================

[View Source](https://github.com/mkaput/elixir-bimap/blob/v1.2.2/lib/bimap.ex#L534 "View Source")

```

@spec delete_key([t](#t:t/0)(), [k](#t:k/0)()) :: [t](#t:t/0)()

```

Deletes `{key, _}` pair from `bimap`.

If the `key` does not exist, returns `bimap` unchanged.

[examples](#delete_key/2-examples)

 Examples

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

```

iex> bimap = BiMap.new([a: 1, b: 2])

iex> BiMap.delete\_key(bimap, :b)

#BiMap<[a: 1]>

iex> BiMap.delete\_key(bimap, :c)

#BiMap<[a: 1, b: 2]>

```

[Link to this function](#delete_value/2 "Link to this function")

delete\_value(bimap, value)

===========================

[View Source](https://github.com/mkaput/elixir-bimap/blob/v1.2.2/lib/bimap.ex#L558 "View Source")

```

@spec delete_value([t](#t:t/0)(), [v](#t:v/0)()) :: [t](#t:t/0)()

```

Deletes `{_, value}` pair from `bimap`.

If the `value` does not exist, returns `bimap` unchanged.

[examples](#delete_value/2-examples)

 Examples

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

```

iex> bimap = BiMap.new([a: 1, b: 2])

iex> BiMap.delete\_value(bimap, 2)

#BiMap<[a: 1]>

iex> BiMap.delete\_value(bimap, 3)

#BiMap<[a: 1, b: 2]>

```

[Link to this function](#equal?/2 "Link to this function")

equal?(bimap1, bimap2)

======================

[View Source](https://github.com/mkaput/elixir-bimap/blob/v1.2.2/lib/bimap.ex#L261 "View Source")

```

@spec equal?([t](#t:t/0)(), [t](#t:t/0)()) :: [boolean](https://hexdocs.pm/elixir/typespecs.html#built-in-types)()

```

Checks if two bimaps are equal.

Two bimaps are considered to be equal if they contain the same keys and those

keys contain the same values.

[examples](#equal?/2-examples)

 Examples

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

```

iex> Map.equal?(BiMap.new([a: 1, b: 2]), BiMap.new([b: 2, a: 1]))

true

iex> Map.equal?(BiMap.new([a: 1, b: 2]), BiMap.new([b: 1, a: 2]))

false

```

[Link to this function](#fetch!/2 "Link to this function")

fetch!(bimap, key)

==================

[View Source](https://github.com/mkaput/elixir-bimap/blob/v1.2.2/lib/bimap.ex#L351 "View Source")

```

@spec fetch!([t](#t:t/0)(), [k](#t:k/0)()) :: [v](#t:v/0)()

```

Fetches the value for specific `key` in `bimap`.

Raises [`ArgumentError`](https://hexdocs.pm/elixir/ArgumentError.html) if the key is absent.

[examples](#fetch!/2-examples)

 Examples

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

```

iex> bimap = BiMap.new([a: 1])

iex> BiMap.fetch!(bimap, :a)

1

```

[Link to this function](#fetch/2 "Link to this function")

fetch(bimap, key)

=================

[View Source](https://github.com/mkaput/elixir-bimap/blob/v1.2.2/lib/bimap.ex#L333 "View Source")

```

@spec fetch([t](#t:t/0)(), [k](#t:k/0)()) :: {:ok, [v](#t:v/0)()} | :error

```

Fetches the value for specific `key` in `bimap`

If `key` is present in `bimap` with value `value`, then `{:ok, value}` is

returned. Otherwise, `:error` is returned.

[examples](#fetch/2-examples)

 Examples

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

```

iex> BiMap.fetch(BiMap.new(), :a)

:error

iex> bimap = BiMap.new([a: 1])

iex> BiMap.fetch(bimap, :a)

{:ok, 1}

iex> BiMap.fetch(bimap, :b)

:error

```

[Link to this function](#fetch_key!/2 "Link to this function")

fetch\_key!(bimap, value)

=========================

[View Source](https://github.com/mkaput/elixir-bimap/blob/v1.2.2/lib/bimap.ex#L394 "View Source")

```

@spec fetch_key!([t](#t:t/0)(), [v](#t:v/0)()) :: [k](#t:k/0)()

```

Fetches the key for specific `value` in `bimap`.

Raises [`ArgumentError`](https://hexdocs.pm/elixir/ArgumentError.html) if the value is absent. This function is exact mirror of [`fetch!/2`](#fetch!/2).

[examples](#fetch_key!/2-examples)

 Examples

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

```

iex> bimap = BiMap.new([a: 1])

iex> BiMap.fetch\_key!(bimap, 1)

:a

```

[Link to this function](#fetch_key/2 "Link to this function")

fetch\_key(bimap, value)

========================

[View Source](https://github.com/mkaput/elixir-bimap/blob/v1.2.2/lib/bimap.ex#L376 "View Source")

```

@spec fetch_key([t](#t:t/0)(), [v](#t:v/0)()) :: {:ok, [k](#t:k/0)()} | :error

```

Fetches the key for specific `value` in `bimap`

This function is exact mirror of [`fetch/2`](#fetch/2).

[examples](#fetch_key/2-examples)

 Examples

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

```

iex> BiMap.fetch\_key(BiMap.new, 1)

:error

iex> bimap = BiMap.new([a: 1])

iex> BiMap.fetch\_key(bimap, 1)

{:ok, :a}

iex> BiMap.fetch\_key(bimap, 2)

:error

```

[Link to this function](#get/3 "Link to this function")

get(bimap, key, default \\ nil)

===============================

[View Source](https://github.com/mkaput/elixir-bimap/blob/v1.2.2/lib/bimap.ex#L286 "View Source")

```

@spec get([t](#t:t/0)(), [k](#t:k/0)(), [v](#t:v/0)()) :: [v](#t:v/0)()

```

Gets the value for specific `key` in `bimap`

If `key` is present in `bimap` with value `value`, then `value` is returned.

Otherwise, `default` is returned (which is `nil` unless specified otherwise).

[examples](#get/3-examples)

 Examples

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

```

iex> BiMap.get(BiMap.new(), :a)

nil

iex> bimap = BiMap.new([a: 1])

iex> BiMap.get(bimap, :a)

1

iex> BiMap.get(bimap, :b)

nil

iex> BiMap.get(bimap, :b, 3)

3

```

[Link to this function](#get_key/3 "Link to this function")

get\_key(bimap, value, default \\ nil)

======================================

[View Source](https://github.com/mkaput/elixir-bimap/blob/v1.2.2/lib/bimap.ex#L310 "View Source")

```

@spec get_key([t](#t:t/0)(), [v](#t:v/0)(), [k](#t:k/0)()) :: [k](#t:k/0)()

```

Gets the key for specific `value` in `bimap`

This function is exact mirror of [`get/3`](#get/3).

[examples](#get_key/3-examples)

 Examples

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

```

iex> BiMap.get\_key(BiMap.new, 1)

nil

iex> bimap = BiMap.new([a: 1])

iex> BiMap.get\_key(bimap, 1)

:a

iex> BiMap.get\_key(bimap, 2)

nil

iex> BiMap.get\_key(bimap, 2, :b)

:b

```

[Link to this function](#has_key?/2 "Link to this function")

has\_key?(bimap, key)

=====================

[View Source](https://github.com/mkaput/elixir-bimap/blob/v1.2.2/lib/bimap.ex#L223 "View Source")

```

@spec has_key?([t](#t:t/0)(), [k](#t:k/0)()) :: [boolean](https://hexdocs.pm/elixir/typespecs.html#built-in-types)()

```

Checks if `bimap` contains `key`.

[examples](#has_key?/2-examples)

 Examples

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

```

iex> bimap = BiMap.new([a: "foo", b: "bar"])

iex> BiMap.has\_key?(bimap, :a)

true

iex> BiMap.has\_key?(bimap, :x)

false

```

[Link to this function](#has_value?/2 "Link to this function")

has\_value?(bimap, value)

=========================

[View Source](https://github.com/mkaput/elixir-bimap/blob/v1.2.2/lib/bimap.ex#L241 "View Source")

```

@spec has_value?([t](#t:t/0)(), [v](#t:v/0)()) :: [boolean](https://hexdocs.pm/elixir/typespecs.html#built-in-types)()

```

Checks if `bimap` contains `value`.

[examples](#has_value?/2-examples)

 Examples

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

```

iex> bimap = BiMap.new([a: "foo", b: "bar"])

iex> BiMap.has\_value?(bimap, "foo")

true

iex> BiMap.has\_value?(bimap, "moo")

false

```

[Link to this function](#keys/1 "Link to this function")

keys(bimap)

===========

[View Source](https://github.com/mkaput/elixir-bimap/blob/v1.2.2/lib/bimap.ex#L170 "View Source")

```

@spec keys([t](#t:t/0)()) :: [[k](#t:k/0)()]

```

Returns all keys from `bimap`.

[examples](#keys/1-examples)

 Examples

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

```

iex> bimap = BiMap.new([a: 1, b: 2])

iex> BiMap.keys(bimap)

[:a, :b]

```

[Link to this function](#left/1 "Link to this function")

left(bimap)

===========

[View Source](https://github.com/mkaput/elixir-bimap/blob/v1.2.2/lib/bimap.ex#L144 "View Source")

```

@spec left([t](#t:t/0)()) :: %{required([k](#t:k/0)()) => [v](#t:v/0)()}

```

Returns `key ➜ value` mapping of `bimap`.

[examples](#left/1-examples)

 Examples

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

```

iex> bimap = BiMap.new([a: "foo", b: "bar"])

iex> BiMap.left(bimap)

%{a: "foo", b: "bar"}

```

[Link to this function](#member?/2 "Link to this function")

member?(bimap, kv)

==================

[View Source](https://github.com/mkaput/elixir-bimap/blob/v1.2.2/lib/bimap.ex#L208 "View Source")

```

@spec member?(

  [t](#t:t/0)(),

  {[k](#t:k/0)(), [v](#t:v/0)()}

) :: [boolean](https://hexdocs.pm/elixir/typespecs.html#built-in-types)()

```

Convenience shortcut for [`member?/3`](#member?/3).

[Link to this function](#member?/3 "Link to this function")

member?(bimap, key, value)

==========================

[View Source](https://github.com/mkaput/elixir-bimap/blob/v1.2.2/lib/bimap.ex#L198 "View Source")

```

@spec member?([t](#t:t/0)(), [k](#t:k/0)(), [v](#t:v/0)()) :: [boolean](https://hexdocs.pm/elixir/typespecs.html#built-in-types)()

```

Checks if `bimap` contains `{key, value}` pair.

[examples](#member?/3-examples)

 Examples

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

```

iex> bimap = BiMap.new([a: "foo", b: "bar"])

iex> BiMap.member?(bimap, :a, "foo")

true

iex> BiMap.member?(bimap, :a, "bar")

false

```

[Link to this function](#new/0 "Link to this function")

new()

=====

[View Source](https://github.com/mkaput/elixir-bimap/blob/v1.2.2/lib/bimap.ex#L73 "View Source")

```

@spec new() :: [t](#t:t/0)()

```

Creates a new bimap.

[examples](#new/0-examples)

 Examples

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

```

iex> BiMap.new

#BiMap<[]>

```

[Link to this function](#new/1 "Link to this function")

new(enumerable)

===============

[View Source](https://github.com/mkaput/elixir-bimap/blob/v1.2.2/lib/bimap.ex#L86 "View Source")

```

@spec new([Enum.t](https://hexdocs.pm/elixir/Enum.html#t:t/0)()) :: [t](#t:t/0)()

```

Creates a bimap from `enumerable` of key-value pairs.

Duplicated pairs are removed; the latest one prevails.

[examples](#new/1-examples)

 Examples

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

```

iex> BiMap.new([a: "foo", b: "bar"])

#BiMap<[a: "foo", b: "bar"]>

```

[Link to this function](#new/2 "Link to this function")

new(enumerable, transform)

==========================

[View Source](https://github.com/mkaput/elixir-bimap/blob/v1.2.2/lib/bimap.ex#L105 "View Source")

```

@spec new([Enum.t](https://hexdocs.pm/elixir/Enum.html#t:t/0)(), ([term](https://hexdocs.pm/elixir/typespecs.html#built-in-types)() -> {[k](#t:k/0)(), [v](#t:v/0)()})) :: [t](#t:t/0)()

```

Creates a bimap from `enumerable` via transform function returning key-value

pairs.

[examples](#new/2-examples)

 Examples

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

```

iex> BiMap.new([1, 2, 1], fn x -> {x, x \* 2} end)

#BiMap<[{1, 2}, {2, 4}]>

```

[Link to this function](#put/2 "Link to this function")

put(bimap, kv)

==============

[View Source](https://github.com/mkaput/elixir-bimap/blob/v1.2.2/lib/bimap.ex#L430 "View Source")

```

@spec put(

  [t](#t:t/0)(),

  {[k](#t:k/0)(), [v](#t:v/0)()}

) :: [t](#t:t/0)()

```

Convenience shortcut for [`put/3`](#put/3)

[Link to this function](#put/3 "Link to this function")

put(bimap, key, value)

======================

[View Source](https://github.com/mkaput/elixir-bimap/blob/v1.2.2/lib/bimap.ex#L421 "View Source")

```

@spec put([t](#t:t/0)(), [k](#t:k/0)(), [v](#t:v/0)()) :: [t](#t:t/0)()

```

Inserts `{key, value}` pair into `bimap`.

If either `key` or `value` is already in `bimap`, any overlapping bindings are

deleted.

[examples](#put/3-examples)

 Examples

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

```

iex> bimap = BiMap.new

#BiMap<[]>

iex> bimap = BiMap.put(bimap, :a, 0)

#BiMap<[a: 0]>

iex> bimap = BiMap.put(bimap, :a, 1)

#BiMap<[a: 1]>

iex> BiMap.put(bimap, :b, 1)

#BiMap<[b: 1]>

```

[Link to this function](#put_new_key/3 "Link to this function")

put\_new\_key(bimap, key, value)

================================

[View Source](https://github.com/mkaput/elixir-bimap/blob/v1.2.2/lib/bimap.ex#L455 "View Source")

```

@spec put_new_key([t](#t:t/0)(), [k](#t:k/0)(), [v](#t:v/0)()) :: [t](#t:t/0)()

```

Inserts `{key, value}` pair into `bimap` if `key` is not already in `bimap`.

If `key` already exists in `bimap`, `bimap` is returned unchanged.

If `key` does not exist and `value` is already in `bimap`, any overlapping bindings are

deleted.

[examples](#put_new_key/3-examples)

 Examples

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

```

iex> bimap = BiMap.new

#BiMap<[]>

iex> bimap = BiMap.put\_new\_key(bimap, :a, 0)

#BiMap<[a: 0]>

iex> bimap = BiMap.put\_new\_key(bimap, :a, 1)

#BiMap<[a: 0]>

iex> BiMap.put\_new\_key(bimap, :b, 1)

#BiMap<[a: 0, b: 1]>

iex> BiMap.put\_new\_key(bimap, :c, 1)

#BiMap<[a: 0, c: 1]>

```

[Link to this function](#put_new_value/3 "Link to this function")

put\_new\_value(bimap, key, value)

==================================

[View Source](https://github.com/mkaput/elixir-bimap/blob/v1.2.2/lib/bimap.ex#L485 "View Source")

```

@spec put_new_value([t](#t:t/0)(), [k](#t:k/0)(), [v](#t:v/0)()) :: [t](#t:t/0)()

```

Inserts `{key, value}` pair into `bimap` if `value` is not already in `bimap`.

If `value` already exists in `bimap`, `bimap` is returned unchanged.

If `value` does not exist and `key` is already in `bimap`, any overlapping bindings are

deleted.

[examples](#put_new_value/3-examples)

 Examples

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

```

iex> bimap = BiMap.new

#BiMap<[]>

iex> bimap = BiMap.put\_new\_value(bimap, :a, 0)

#BiMap<[a: 0]>

iex> bimap = BiMap.put\_new\_value(bimap, :a, 1)

#BiMap<[a: 1]>

iex> BiMap.put\_new\_value(bimap, :b, 1)

#BiMap<[a: 1]>

iex> BiMap.put\_new\_value(bimap, :c, 2)

#BiMap<[a: 1, c: 2]>

```

[Link to this function](#right/1 "Link to this function")

right(bimap)

============

[View Source](https://github.com/mkaput/elixir-bimap/blob/v1.2.2/lib/bimap.ex#L157 "View Source")

```

@spec right([t](#t:t/0)()) :: %{required([v](#t:v/0)()) => [k](#t:k/0)()}

```

Returns `value ➜ key` mapping of `bimap`.

[examples](#right/1-examples)

 Examples

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

```

iex> bimap = BiMap.new([a: "foo", b: "bar"])

iex> BiMap.right(bimap)

%{"foo" => :a, "bar" => :b}

```

[Link to this function](#size/1 "Link to this function")

size(bimap)

===========

[View Source](https://github.com/mkaput/elixir-bimap/blob/v1.2.2/lib/bimap.ex#L128 "View Source")

```

@spec size([t](#t:t/0)()) :: [non\_neg\_integer](https://hexdocs.pm/elixir/typespecs.html#basic-types)()

```

Returns the number of elements in `bimap`.

The size of a bimap is the number of key-value pairs that the map contains.

[examples](#size/1-examples)

 Examples

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

```

iex> BiMap.size(BiMap.new)

0

iex> bimap = BiMap.new([a: "foo", b: "bar"])

iex> BiMap.size(bimap)

2

```

[Link to this function](#to_list/1 "Link to this function")

to\_list(bimap)

===============

[View Source](https://github.com/mkaput/elixir-bimap/blob/v1.2.2/lib/bimap.ex#L585 "View Source")

```

@spec to_list([t](#t:t/0)()) :: [{[k](#t:k/0)(), [v](#t:v/0)()}]

```

Returns list of unique key-value pairs in `bimap`.

[examples](#to_list/1-examples)

 Examples

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

```

iex> bimap = BiMap.new([a: "foo", b: "bar"])

iex> BiMap.to\_list(bimap)

[a: "foo", b: "bar"]

```

[Link to this function](#values/1 "Link to this function")

values(bimap)

=============

[View Source](https://github.com/mkaput/elixir-bimap/blob/v1.2.2/lib/bimap.ex#L183 "View Source")

```

@spec values([t](#t:t/0)()) :: [[v](#t:v/0)()]

```

Returns all values from `bimap`.

[examples](#values/1-examples)

 Examples

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

```

iex> bimap = BiMap.new([a: 1, b: 2])

iex> BiMap.values(bimap)

[1, 2]

```





BiMultiMap — BiMap v1.2.2

 try {

 var settings = JSON.parse(localStorage.getItem('ex\_doc:settings') || '{}');

 if (settings.theme === 'dark' ||

 ((settings.theme === 'system' || settings.theme == null) &&

 window.matchMedia('(prefers-color-scheme: dark)').matches)

 ) {

 document.body.classList.add('dark')

 }

 } catch (error) { }

 

Settings

[View Source](https://github.com/mkaput/elixir-bimap/blob/v1.2.2/lib/bimultimap.ex#L1 "View Source")

BiMultiMap

(BiMap v1.2.2)

===========================================================================================================================================

Bi-directional multimap implementation backed by two multimaps.

Entries in bimap do not follow any order.

BiMultiMaps do not impose any restriction on the key and value type: anything

can be a key in a bimap, and also anything can be a value.

BiMultiMaps differ from [`BiMap`](BiMap.html)s by disallowing duplicates only among key-value

pairs, not among keys and values separately. This means it is possible to store

`[(A, B), (A, C)]` or `[(X, Z), (Y, Z)]` in BiMultiMap.

Keys and values are compared using the exact-equality operator (`===`).

[example](#module-example)

 Example

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

```

iex> mm = BiMultiMap.new(a: 1, b: 2, b: 1)

#BiMultiMap<[a: 1, b: 1, b: 2]>

iex> BiMultiMap.get(mm, :a)

[1]

iex> BiMultiMap.get\_keys(mm, 1)

[:a, :b]

iex> BiMultiMap.put(mm, :a, 3)

#BiMultiMap<[a: 1, a: 3, b: 1, b: 2]>

```

[protocols](#module-protocols)

 Protocols

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

[`BiMultiMap`](BiMultiMap.html#content) implements [`Enumerable`](https://hexdocs.pm/elixir/Enumerable.html), [`Collectable`](https://hexdocs.pm/elixir/Collectable.html) and [`Inspect`](https://hexdocs.pm/elixir/Inspect.html) protocols.

[Link to this section](#summary)

 Summary

==========================================

[Types](#types)

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

[k()](#t:k/0)

Key type

[t()](#t:t/0)

[t(k, v)](#t:t/2)

[v()](#t:v/0)

Value type

[Functions](#functions)

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

[delete(bimultimap, kv)](#delete/2)

Convenience shortcut for [`delete/3`](#delete/3).

[delete(bimultimap, key, value)](#delete/3)

Deletes `{key, value}` pair from `bimultimap`.

[delete\_key(bimultimap, key)](#delete_key/2)

Deletes `{key, _}` pair from `bimultimap`.

[delete\_value(bimultimap, value)](#delete_value/2)

Deletes `{_, value}` pair from `bimultimap`.

[equal?(bimultimap1, bimultimap2)](#equal?/2)

Checks if two bimultimaps are equal.

[fetch!(bimultimap, key)](#fetch!/2)

Fetches all values for specific `key` in `bimultimap`

[fetch(bimultimap, key)](#fetch/2)

Fetches all values for specific `key` in `bimultimap`

[fetch\_keys!(bimultimap, value)](#fetch_keys!/2)

Fetches all keys for specific `value` in `bimultimap`

[fetch\_keys(bimultimap, value)](#fetch_keys/2)

Fetches all keys for specific `value` in `bimultimap`

[get(bimultimap, key, default \\ [])](#get/3)

Gets all values for specific `key` in `bimultimap`

[get\_keys(bimultimap, value, default \\ [])](#get_keys/3)

Gets all keys for specific `value` in `bimultimap`

[has\_key?(bimultimap, key)](#has_key?/2)

Checks if `bimultimap` contains `key`.

[has\_value?(bimultimap, value)](#has_value?/2)

Checks if `bimultimap` contains `value`.

[keys(bimultimap)](#keys/1)

Returns all unique keys from `bimultimap`.

[left(bimultimap)](#left/1)

Returns `key ➜ [value]` mapping of `bimultimap`.

[member?(bimultimap, kv)](#member?/2)

Convenience shortcut for [`member?/3`](#member?/3).

[member?(bimultimap, key, value)](#member?/3)

Checks if `bimultimap` contains `{key, value}` pair.

[new()](#new/0)

Creates a new bimultimap.

[new(enumerable)](#new/1)

Creates a bimultimap from `enumerable` of key-value pairs.

[new(enumerable, transform)](#new/2)

Creates a bimultimap from `enumerable` via transform function returning

key-value pairs.

[put(bimultimap, kv)](#put/2)

Convenience shortcut for [`put/3`](#put/3)

[put(bimultimap, key, value)](#put/3)

Inserts `{key, value}` pair into `bimultimap`.

[right(bimultimap)](#right/1)

Returns `value ➜ key` mapping of `bimultimap`.

[size(bimultimap)](#size/1)

Returns the number of elements in `bimultimap`.

[to\_list(bimultimap)](#to_list/1)

Returns list of unique key-value pairs in `bimultimap`.

[values(bimultimap)](#values/1)

Returns all unique values from `bimultimap`.

[Link to this section](#types)

Types

=====================================

[Link to this type](#t:k/0 "Link to this type")

k()

===

[View Source](https://github.com/mkaput/elixir-bimap/blob/v1.2.2/lib/bimultimap.ex#L33 "View Source")

```

@type k() :: [term](https://hexdocs.pm/elixir/typespecs.html#built-in-types)()

```

Key type

[Link to this type](#t:t/0 "Link to this type")

t()

===

[View Source](https://github.com/mkaput/elixir-bimap/blob/v1.2.2/lib/bimultimap.ex#L53 "View Source")

```

@type t() :: [t](#t:t/2)([term](https://hexdocs.pm/elixir/typespecs.html#built-in-types)(), [term](https://hexdocs.pm/elixir/typespecs.html#built-in-types)())

```

[Link to this type](#t:t/2 "Link to this type")

t(k, v)

=======

[View Source](https://github.com/mkaput/elixir-bimap/blob/v1.2.2/lib/bimultimap.ex#L47 "View Source")

```

@type t(k, v) :: %BiMultiMap{

  keys: internal_keys(k, v),

  size: internal_size(),

  values: internal_values(k, v)

}

```

[Link to this type](#t:v/0 "Link to this type")

v()

===

[View Source](https://github.com/mkaput/elixir-bimap/blob/v1.2.2/lib/bimultimap.ex#L36 "View Source")

```

@type v() :: [term](https://hexdocs.pm/elixir/typespecs.html#built-in-types)()

```

Value type

[Link to this section](#functions)

Functions

=============================================

[Link to this function](#delete/2 "Link to this function")

delete(bimultimap, kv)

======================

[View Source](https://github.com/mkaput/elixir-bimap/blob/v1.2.2/lib/bimultimap.ex#L592 "View Source")

```

@spec delete(

  [t](#t:t/0)(),

  {[k](#t:k/0)(), [v](#t:v/0)()}

) :: [t](#t:t/0)()

```

Convenience shortcut for [`delete/3`](#delete/3).

[Link to this function](#delete/3 "Link to this function")

delete(bimultimap, key, value)

==============================

[View Source](https://github.com/mkaput/elixir-bimap/blob/v1.2.2/lib/bimultimap.ex#L498 "View Source")

```

@spec delete([t](#t:t/0)(), [k](#t:k/0)(), [v](#t:v/0)()) :: [t](#t:t/0)()

```

Deletes `{key, value}` pair from `bimultimap`.

If the `key` does not exist, or `value` does not match, returns `bimultimap`

unchanged.

[examples](#delete/3-examples)

 Examples

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

```

iex> bimultimap = BiMultiMap.new([a: 1, b: 2, c: 2])

iex> BiMultiMap.delete(bimultimap, :b, 2)

#BiMultiMap<[a: 1, c: 2]>

iex> BiMultiMap.delete(bimultimap, :c, 3)

#BiMultiMap<[a: 1, b: 2, c: 2]>

```

[Link to this function](#delete_key/2 "Link to this function")

delete\_key(bimultimap, key)

============================

[View Source](https://github.com/mkaput/elixir-bimap/blob/v1.2.2/lib/bimultimap.ex#L550 "View Source")

```

@spec delete_key([t](#t:t/0)(), [k](#t:k/0)()) :: [t](#t:t/0)()

```

Deletes `{key, _}` pair from `bimultimap`.

If the `key` does not exist, returns `bimultimap` unchanged.

[examples](#delete_key/2-examples)

 Examples

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

```

iex> bimultimap = BiMultiMap.new([a: 1, b: 2, b: 3])

iex> BiMultiMap.delete\_key(bimultimap, :b)

#BiMultiMap<[a: 1]>

iex> BiMultiMap.delete\_key(bimultimap, :c)

#BiMultiMap<[a: 1, b: 2, b: 3]>

```

[Link to this function](#delete_value/2 "Link to this function")

delete\_value(bimultimap, value)

================================

[View Source](https://github.com/mkaput/elixir-bimap/blob/v1.2.2/lib/bimultimap.ex#L576 "View Source")

```

@spec delete_value([t](#t:t/0)(), [v](#t:v/0)()) :: [t](#t:t/0)()

```

Deletes `{_, value}` pair from `bimultimap`.

If the `value` does not exist, returns `bimultimap` unchanged.

[examples](#delete_value/2-examples)

 Examples

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

```

iex> bimultimap = BiMultiMap.new([a: 1, b: 2, c: 1])

iex> BiMultiMap.delete\_value(bimultimap, 1)

#BiMultiMap<[b: 2]>

iex> BiMultiMap.delete\_value(bimultimap, 3)

#BiMultiMap<[a: 1, b: 2, c: 1]>

```

[Link to this function](#equal?/2 "Link to this function")

equal?(bimultimap1, bimultimap2)

================================

[View Source](https://github.com/mkaput/elixir-bimap/blob/v1.2.2/lib/bimultimap.ex#L264 "View Source")

```

@spec equal?([t](#t:t/0)(), [t](#t:t/0)()) :: [boolean](https://hexdocs.pm/elixir/typespecs.html#built-in-types)()

```

Checks if two bimultimaps are equal.

Two bimultimaps are considered to be equal if they contain the same keys and

those keys are bound with the same values.

[examples](#equal?/2-examples)

 Examples

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

```

iex> Map.equal?(BiMultiMap.new([a: 1, b: 2, b: 3]), BiMultiMap.new([b: 2, b: 3, a: 1]))

true

iex> Map.equal?(BiMultiMap.new([a: 1, b: 2, b: 3]), BiMultiMap.new([b: 1, b: 3, a: 2]))

false

```

[Link to this function](#fetch!/2 "Link to this function")

fetch!(bimultimap, key)

=======================

[View Source](https://github.com/mkaput/elixir-bimap/blob/v1.2.2/lib/bimultimap.ex#L372 "View Source")

```

@spec fetch!([t](#t:t/0)(), [k](#t:k/0)()) :: [[v](#t:v/0)()]

```

Fetches all values for specific `key` in `bimultimap`

Raises [`ArgumentError`](https://hexdocs.pm/elixir/ArgumentError.html) if the key is absent.

[examples](#fetch!/2-examples)

 Examples

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

```

iex> bimultimap = BiMultiMap.new([a: 1, c: 1, c: 2])

iex> BiMultiMap.fetch!(bimultimap, :a)

[1]

iex> BiMultiMap.fetch!(bimultimap, :c)

[1, 2]

```

[Link to this function](#fetch/2 "Link to this function")

fetch(bimultimap, key)

======================

[View Source](https://github.com/mkaput/elixir-bimap/blob/v1.2.2/lib/bimultimap.ex#L349 "View Source")

```

@spec fetch([t](#t:t/0)(), [k](#t:k/0)()) :: {:ok, [[v](#t:v/0)()]} | :error

```

Fetches all values for specific `key` in `bimultimap`

If `key` is present in `bimultimap` with values `values`, then `{:ok, values}`

is returned. Otherwise, `:error` is returned.

[examples](#fetch/2-examples)

 Examples

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

```

iex> BiMultiMap.fetch(BiMultiMap.new(), :a)

:error

iex> bimultimap = BiMultiMap.new([a: 1, c: 1, c: 2])

iex> BiMultiMap.fetch(bimultimap, :a)

{:ok, [1]}

iex> BiMultiMap.fetch(bimultimap, :b)

:error

iex> BiMultiMap.fetch(bimultimap, :c)

{:ok, [1, 2]}

```

[Link to this function](#fetch_keys!/2 "Link to this function")

fetch\_keys!(bimultimap, value)

===============================

[View Source](https://github.com/mkaput/elixir-bimap/blob/v1.2.2/lib/bimultimap.ex#L422 "View Source")

```

@spec fetch_keys!([t](#t:t/0)(), [v](#t:v/0)()) :: [[k](#t:k/0)()]

```

Fetches all keys for specific `value` in `bimultimap`

Raises [`ArgumentError`](https://hexdocs.pm/elixir/ArgumentError.html) if the key is absent. This function is exact mirror of [`fetch!/2`](#fetch!/2).

[examples](#fetch_keys!/2-examples)

 Examples

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

```

iex> bimultimap = BiMultiMap.new([a: 1, c: 3, d: 3])

iex> BiMultiMap.fetch\_keys!(bimultimap, 1)

[:a]

iex> BiMultiMap.fetch\_keys!(bimultimap, 3)

[:c, :d]

```

[Link to this function](#fetch_keys/2 "Link to this function")

fetch\_keys(bimultimap, value)

==============================

[View Source](https://github.com/mkaput/elixir-bimap/blob/v1.2.2/lib/bimultimap.ex#L399 "View Source")

```

@spec fetch_keys([t](#t:t/0)(), [v](#t:v/0)()) :: {:ok, [[k](#t:k/0)()]} | :error

```

Fetches all keys for specific `value` in `bimultimap`

This function is exact mirror of [`fetch/2`](#fetch/2).

[examples](#fetch_keys/2-examples)

 Examples

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

```

iex> BiMultiMap.fetch\_keys(BiMultiMap.new, 1)

:error

iex> bimultimap = BiMultiMap.new([a: 1, c: 3, d: 3])

iex> BiMultiMap.fetch\_keys(bimultimap, 1)

{:ok, [:a]}

iex> BiMultiMap.fetch\_keys(bimultimap, 2)

:error

iex> BiMultiMap.fetch\_keys(bimultimap, 3)

{:ok, [:c, :d]}

```

[Link to this function](#get/3 "Link to this function")

get(bimultimap, key, default \\ [])

===================================

[View Source](https://github.com/mkaput/elixir-bimap/blob/v1.2.2/lib/bimultimap.ex#L292 "View Source")

```

@spec get([t](#t:t/0)(), [k](#t:k/0)(), [any](https://hexdocs.pm/elixir/typespecs.html#basic-types)()) :: [[v](#t:v/0)()] | [any](https://hexdocs.pm/elixir/typespecs.html#basic-types)()

```

Gets all values for specific `key` in `bimultimap`

If `key` is present in `bimultimap` with values `values`, then `values` are

returned. Otherwise, `default` is returned (which is `[]` unless specified

otherwise).

[examples](#get/3-examples)

 Examples

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

```

iex> BiMultiMap.get(BiMultiMap.new(), :a)

[]

iex> bimultimap = BiMultiMap.new([a: 1, c: 1, c: 2])

iex> BiMultiMap.get(bimultimap, :a)

[1]

iex> BiMultiMap.get(bimultimap, :b)

[]

iex> BiMultiMap.get(bimultimap, :b, 3)

3

iex> BiMultiMap.get(bimultimap, :c)

[1, 2]

```

[Link to this function](#get_keys/3 "Link to this function")

get\_keys(bimultimap, value, default \\ [])

===========================================

[View Source](https://github.com/mkaput/elixir-bimap/blob/v1.2.2/lib/bimultimap.ex#L321 "View Source")

```

@spec get_keys([t](#t:t/0)(), [v](#t:v/0)(), [any](https://hexdocs.pm/elixir/typespecs.html#basic-types)()) :: [[k](#t:k/0)()] | [any](https://hexdocs.pm/elixir/typespecs.html#basic-types)()

```

Gets all keys for specific `value` in `bimultimap`

This function is exact mirror of [`get/3`](#get/3).

[examples](#get_keys/3-examples)

 Examples

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

```

iex> BiMultiMap.get\_keys(BiMultiMap.new, 1)

[]

iex> bimultimap = BiMultiMap.new([a: 1, c: 3, d: 3])

iex> BiMultiMap.get\_keys(bimultimap, 1)

[:a]

iex> BiMultiMap.get\_keys(bimultimap, 2)

[]

iex> BiMultiMap.get\_keys(bimultimap, 2, :b)

:b

iex> BiMultiMap.get\_keys(bimultimap, 3)

[:c, :d]

```

[Link to this function](#has_key?/2 "Link to this function")

has\_key?(bimultimap, key)

==========================

[View Source](https://github.com/mkaput/elixir-bimap/blob/v1.2.2/lib/bimultimap.ex#L226 "View Source")

```

@spec has_key?([t](#t:t/0)(), [k](#t:k/0)()) :: [boolean](https://hexdocs.pm/elixir/typespecs.html#built-in-types)()

```

Checks if `bimultimap` contains `key`.

[examples](#has_key?/2-examples)

 Examples

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

```

iex> bimultimap = BiMultiMap.new([a: "foo", b: "bar"])

iex> BiMultiMap.has\_key?(bimultimap, :a)

true

iex> BiMultiMap.has\_key?(bimultimap, :x)

false

```

[Link to this function](#has_value?/2 "Link to this function")

has\_value?(bimultimap, value)

==============================

[View Source](https://github.com/mkaput/elixir-bimap/blob/v1.2.2/lib/bimultimap.ex#L244 "View Source")

```

@spec has_value?([t](#t:t/0)(), [v](#t:v/0)()) :: [boolean](https://hexdocs.pm/elixir/typespecs.html#built-in-types)()

```

Checks if `bimultimap` contains `value`.

[examples](#has_value?/2-examples)

 Examples

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

```

iex> bimultimap = BiMultiMap.new([a: "foo", b: "bar"])

iex> BiMultiMap.has\_value?(bimultimap, "foo")

true

iex> BiMultiMap.has\_value?(bimultimap, "moo")

false

```

[Link to this function](#keys/1 "Link to this function")

keys(bimultimap)

================

[View Source](https://github.com/mkaput/elixir-bimap/blob/v1.2.2/lib/bimultimap.ex#L171 "View Source")

```

@spec keys([t](#t:t/0)()) :: [[k](#t:k/0)()]

```

Returns all unique keys from `bimultimap`.

[examples](#keys/1-examples)

 Examples

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

```

iex> bimultimap = BiMultiMap.new([a: 1, b: 2, b: 3])

iex> BiMultiMap.keys(bimultimap)

[:a, :b]

```

[Link to this function](#left/1 "Link to this function")

left(bimultimap)

================

[View Source](https://github.com/mkaput/elixir-bimap/blob/v1.2.2/lib/bimultimap.ex#L135 "View Source")

```

@spec left([t](#t:t/0)()) :: %{required([k](#t:k/0)()) => [[v](#t:v/0)()]}

```

Returns `key ➜ [value]` mapping of `bimultimap`.

[examples](#left/1-examples)

 Examples

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

```

iex> bimultimap = BiMultiMap.new([a: "foo", b: "bar", b: "moo"])

iex> BiMultiMap.left(bimultimap)

%{a: ["foo"], b: ["bar", "moo"]}

```

[Link to this function](#member?/2 "Link to this function")

member?(bimultimap, kv)

=======================

[View Source](https://github.com/mkaput/elixir-bimap/blob/v1.2.2/lib/bimultimap.ex#L211 "View Source")

```

@spec member?(

  [t](#t:t/0)(),

  {[k](#t:k/0)(), [v](#t:v/0)()}

) :: [boolean](https://hexdocs.pm/elixir/typespecs.html#built-in-types)()

```

Convenience shortcut for [`member?/3`](#member?/3).

[Link to this function](#member?/3 "Link to this function")

member?(bimultimap, key, value)

===============================

[View Source](https://github.com/mkaput/elixir-bimap/blob/v1.2.2/lib/bimultimap.ex#L201 "View Source")

```

@spec member?([t](#t:t/0)(), [k](#t:k/0)(), [v](#t:v/0)()) :: [boolean](https://hexdocs.pm/elixir/typespecs.html#built-in-types)()

```

Checks if `bimultimap` contains `{key, value}` pair.

[examples](#member?/3-examples)

 Examples

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

```

iex> bimultimap = BiMultiMap.new([a: "foo", a: "moo", b: "bar"])

iex> BiMultiMap.member?(bimultimap, :a, "foo")

true

iex> BiMultiMap.member?(bimultimap, :a, "moo")

true

iex> BiMultiMap.member?(bimultimap, :a, "bar")

false

```

[Link to this function](#new/0 "Link to this function")

new()

=====

[View Source](https://github.com/mkaput/elixir-bimap/blob/v1.2.2/lib/bimultimap.ex#L66 "View Source")

```

@spec new() :: [t](#t:t/0)()

```

Creates a new bimultimap.

[examples](#new/0-examples)

 Examples

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

```

iex> BiMultiMap.new

#BiMultiMap<[]>

```

[Link to this function](#new/1 "Link to this function")

new(enumerable)

===============

[View Source](https://github.com/mkaput/elixir-bimap/blob/v1.2.2/lib/bimultimap.ex#L79 "View Source")

```

@spec new([Enum.t](https://hexdocs.pm/elixir/Enum.html#t:t/0)()) :: [t](#t:t/0)()

```

Creates a bimultimap from `enumerable` of key-value pairs.

Duplicated pairs are removed; the latest one prevails.

[examples](#new/1-examples)

 Examples

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

```

iex> BiMultiMap.new([a: 1, a: 2])

#BiMultiMap<[a: 1, a: 2]>

```

[Link to this function](#new/2 "Link to this function")

new(enumerable, transform)

==========================

[View Source](https://github.com/mkaput/elixir-bimap/blob/v1.2.2/lib/bimultimap.ex#L98 "View Source")

```

@spec new([Enum.t](https://hexdocs.pm/elixir/Enum.html#t:t/0)(), ([term](https://hexdocs.pm/elixir/typespecs.html#built-in-types)() -> {[k](#t:k/0)(), [v](#t:v/0)()})) :: [t](#t:t/0)()

```

Creates a bimultimap from `enumerable` via transform function returning

key-value pairs.

[examples](#new/2-examples)

 Examples

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

```

iex> BiMultiMap.new([1, 2, 1], fn x -> {x, x \* 2} end)

#BiMultiMap<[{1, 2}, {2, 4}]>

```

[Link to this function](#put/2 "Link to this function")

put(bimultimap, kv)

===================

[View Source](https://github.com/mkaput/elixir-bimap/blob/v1.2.2/lib/bimultimap.ex#L480 "View Source")

```

@spec put(

  [t](#t:t/0)(),

  {[k](#t:k/0)(), [v](#t:v/0)()}

) :: [t](#t:t/0)()

```

Convenience shortcut for [`put/3`](#put/3)

[Link to this function](#put/3 "Link to this function")

put(bimultimap, key, value)

===========================

[View Source](https://github.com/mkaput/elixir-bimap/blob/v1.2.2/lib/bimultimap.ex#L451 "View Source")

```

@spec put([t](#t:t/0)(), [k](#t:k/0)(), [v](#t:v/0)()) :: [t](#t:t/0)()

```

Inserts `{key, value}` pair into `bimultimap`.

If `{key, value}` is already in `bimultimap`, it is deleted.

[examples](#put/3-examples)

 Examples

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

```

iex> bimultimap = BiMultiMap.new

#BiMultiMap<[]>

iex> bimultimap = BiMultiMap.put(bimultimap, :a, 1)

#BiMultiMap<[a: 1]>

iex> bimultimap = BiMultiMap.put(bimultimap, :a, 2)

#BiMultiMap<[a: 1, a: 2]>

iex> BiMultiMap.put(bimultimap, :b, 2)

#BiMultiMap<[a: 1, a: 2, b: 2]>

```

[Link to this function](#right/1 "Link to this function")

right(bimultimap)

=================

[View Source](https://github.com/mkaput/elixir-bimap/blob/v1.2.2/lib/bimultimap.ex#L153 "View Source")

```

@spec right([t](#t:t/0)()) :: %{required([v](#t:v/0)()) => [[k](#t:k/0)()]}

```

Returns `value ➜ key` mapping of `bimultimap`.

[examples](#right/1-examples)

 Examples

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

```

iex> bimultimap = BiMultiMap.new([a: "foo", b: "bar", c: "bar"])

iex> BiMultiMap.right(bimultimap)

%{"foo" => [:a], "bar" => [:b, :c]}

```

[Link to this function](#size/1 "Link to this function")

size(bimultimap)

================

[View Source](https://github.com/mkaput/elixir-bimap/blob/v1.2.2/lib/bimultimap.ex#L122 "View Source")

```

@spec size([t](#t:t/0)()) :: [non\_neg\_integer](https://hexdocs.pm/elixir/typespecs.html#basic-types)()

```

Returns the number of elements in `bimultimap`.

The size of a bimultimap is the number of key-value pairs that the map

contains.

[examples](#size/1-examples)

 Examples

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

```

iex> BiMultiMap.size(BiMultiMap.new)

0

iex> bimultimap = BiMultiMap.new([a: "foo", a: "bar"])

iex> BiMultiMap.size(bimultimap)

2

```

[Link to this function](#to_list/1 "Link to this function")

to\_list(bimultimap)

====================

[View Source](https://github.com/mkaput/elixir-bimap/blob/v1.2.2/lib/bimultimap.ex#L605 "View Source")

```

@spec to_list([t](#t:t/0)()) :: [{[k](#t:k/0)(), [v](#t:v/0)()}]

```

Returns list of unique key-value pairs in `bimultimap`.

[examples](#to_list/1-examples)

 Examples

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

```

iex> bimultimap = BiMultiMap.new([a: "foo", b: "bar"])

iex> BiMultiMap.to\_list(bimultimap)

[a: "foo", b: "bar"]

```

[Link to this function](#values/1 "Link to this function")

values(bimultimap)

==================

[View Source](https://github.com/mkaput/elixir-bimap/blob/v1.2.2/lib/bimultimap.ex#L184 "View Source")

```

@spec values([t](#t:t/0)()) :: [[v](#t:v/0)()]

```

Returns all unique values from `bimultimap`.

[examples](#values/1-examples)

 Examples

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

```

iex> bimultimap = BiMultiMap.new([a: 1, b: 2, c: 2])

iex> BiMultiMap.values(bimultimap)

[1, 2]

```

