# Functions

**`equals(mixed $a, mixed $b): bool`**

It's a very useful one, especially when you have to deal with different types of values.&#x20;

Returns true when one of the conditions is met:

* if `$a` implements `Equatable` and is equal with `$b`
* if `$a` and `$b` are equal, and of the same type `===`

```php
use function Jungi\Common\equals;

/** @implements Equatable<self> */
class ContactInformation implements Equatable
{
    public function __construct(
        private Phone $phone,
        private ?Phone $mobile = null
    ) {}
    
    public function equals(self $other): bool
    {
        return $this->phone->equals($other->phone)
            && equals($this->mobile, $other->mobile);
    }
}

$a = new ContactInformation(new Phone('(321) 456-1234'), new Phone('(886) 456-6543'));
$b = new ContactInformation(new Phone('(321) 456-1234'), new Phone('(886) 456-6543'));
assert(true === equals($a, $b);

$a = new ContactInformation(new Phone('(321) 456-1234'));
$b = new ContactInformation(new Phone('(321) 456-1234'));
assert(true === equals($a, $b);

$a = new ContactInformation(new Phone('(321) 456-1234'));
$b = new ContactInformation(new Phone('(321) 456-1234'), new Phone('(886) 456-6543'));
assert(false === equals($a, $b);
assert(false === equals($b, $a);
```

**`array_equals(array $a, array $b): bool`**

Returns true if both arrays have the same keys and their values are equal.

```php
use function Jungi\Common\array_equals;

$a = [new Phone('(321) 456-1234'), new Phone('(465) 799-4566')];
$b = [new Phone('(321) 456-1234'), new Phone('(465) 799-4566')];
assert(true === array_equals($a, $b));

$a = [new Phone('(321) 456-1234'), new Phone('(465) 799-4566')];
$b = [new Phone('(321) 456-1234')];
assert(false === array_equals($a, $b));
```

**`in_iterable(mixed $value, iterable $iterable): bool`**

Returns true if a value is present in an iterable.

```php
use function Jungi\Common\in_iterable;

$iterable = [new Phone('(656) 456-7765'), new Phone('(321) 456-1234')];

assert(true === in_iterable(new Phone('(321) 456-1234'), $iterable));
assert(false === in_iterable(new Phone('(232) 456-1234'), $iterable));
```

**`iterable_unique(iterable $iterable): iterable`**

Returns an iterable without duplicates.

```php
use function Jungi\Common\iterable_unique;
use function Jungi\Common\array_equals;

$unique = iterable_unique([
    new Phone('(321) 456-1234'),
    new Phone('(465) 799-4566'),
    new Phone('(321) 456-1234'),
]);
$expected = [
    new Phone('(321) 456-1234'), 
    new Phone('(465) 799-4566'),
];
assert(true === array_equals($expected, $unique));
```

**`iterable_search(mixed $value, iterable $iterable): mixed`**

Returns the first key where the given value is equal. If the value is not found, false is returned.

```php
use function Jungi\Common\iterable_search;

assert(2 === iterable_search(new Phone('(321) 456-1234'), [
    new Phone('(321) 456-1234'),
    new Phone('(465) 799-4566'),
    new Phone('(321) 456-1234'),
]);
assert(false === iterable_search(new Phone('(444) 555-1234'), [
    new Phone('(321) 456-1234'),
    new Phone('(465) 799-4566'),
    new Phone('(321) 456-1234'),
]);
```
