PHPackages                             xcgpseud/hasphp - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. xcgpseud/hasphp

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

xcgpseud/hasphp
===============

Haskell-style List implementations for PHP

v1.0.0(6y ago)04[12 issues](https://github.com/xcgpseud/hasphp/issues)mitPHPCI failing

Since Jan 5Pushed 6y ago1 watchersCompare

[ Source](https://github.com/xcgpseud/hasphp)[ Packagist](https://packagist.org/packages/xcgpseud/hasphp)[ RSS](/packages/xcgpseud-hasphp/feed)WikiDiscussions master Synced 6d ago

READMEChangelog (1)Dependencies (3)Versions (2)Used By (0)

HasPHP
======

[](#hasphp)

#### Type-strict iterable lists with functional functionality provided to them.

[](#type-strict-iterable-lists-with-functional-functionality-provided-to-them)

There are 2 primary ideas behind this library.

1. To provide a way of specifying a type to elements of an array within PHP and forcing adherence to this.
2. To provide a series of functional implementations to an iterable type within PHP.

With HasPHP, these have been combined.

#### Installation

[](#installation)

With composer installed, in your project type:

`composer require xcgpseud/hasphp`

---

#### Usage

[](#usage)

HasPhp will ensure that any items in the initial array are the same type as the one specified. When using Objects - it will ensure that they are all the same type as the first in the array.

Here are a few usage examples:

> To get all odd numbers between 0 and 200, multiply them by 2 and retrieve the sum of said numbers

```
\HasPhp\Types\Ints::with(range(0, 200))
    ->filter(fn (int $i): bool => $i % 2 != 0)
    ->map(fn (int $i): int => $i * 2)
    ->sum();
```

> To get all people above the age of 18

```
\HasPhp\Types\Objects::with($peopleArray)
    ->filter(fn (Person $x): bool => $x->getAge() > 18);
```

Functions such as `map` and `filter` return an IterList so you can chain more functions on to the end. In order to retrieve the array, use `->get()`

**All functions**

Signature is in order of the array within the List -&gt; params -&gt; returns as opposed to Haskell's.

i.e. Haskell's filter is `(a -> bool) -> [a] -> [a]` because it's called like so: `filter (even) [5, 1, 2, 7]`whereas Hasphp's is `[a] -> (a -> bool) -> [a]` because we define the list prior to the function.

FunctionSignatureStringsIntsObjectsDescription`Abs``[a] -> [a] `NoYesNoReturn an IterList containing absolute values.`All``[a] -> (a -> bool) -> bool`YesYesYesReturns true if the predicate applies to every element.`Any``[a] -> (a -> bool) -> bool`YesYesYesReturns true if the predicate applies to any of the elements.`Average``[a] -> a`NoYesNoReturns the average of all values.`Break_``[a] -> (a -> bool) -> ([a], [a])`YesYesYesReturns a tuple of all elements until the first one that matches the predicate, followed by the remaining elements.`Delete``[a] -> a -> [a]`YesYesYesReturns an IterList with the first occurrence of the passed value removed.`Drop``[a] -> Int -> [a]`YesYesYesReturns the suffix of xs after the first n elements.`DropWhile``[a] -> (a -> bool) -> [a]`YesYesYesReturns the suffix of xs after the predicate's first failure.`Elem``[a] -> a -> bool`YesYesYesReturns true if the IterList contains the element; else false.`Filter``[a] -> (a -> bool) -> [a]`YesYesYesReturns and IterList with all of the elements that match the predicate.`Foldl``[b] -> (a -> b -> a) -> a -> a`YesYesYesLeft fold over the IterList to reduce it to one element with a starting value.`Foldr``[a] -> (a -> b -> b) -> b -> b`YesYesYesRight fold over the IterList to reduce it to one element with a starting value.`Foldl1``[a] -> (a -> a -> a) -> a`YesYesYesLeft fold over the IterList to reduce it to one element.`Foldr1``[a] -> (a -> a -> a) -> a`YesYesYesRight fold over the IterList to reduce it to one element.`Group``[a] -> [[a]]`YesYesYesSplit the IterList into a Many List of IterLists of equal, adjacent elements.`GroupBy``[a] -> (a -> a -> bool) -> [[a]]`YesYesYesSplit the IterList into a Many List of IterLists of equal, adjacent elements, with a provided equality predicate.`Head``[a] -> a`YesYesYesReturns the first element of the IterList.`Init``[a] -> [a]`YesYesYesReturns the IterList without its last element.`Inits``[a] -> [[a]]`YesYesYesReturns a Many List of initial segments of its argument IterList, shortest first.`Intercalate``[a] -> [[a]] -> [a]`YesYesYesReturns a Many List with the method receiver List inserted into the IterList at each step.`Intersperse``[a] -> a -> [a]`YesYesYesReturns the IterList with the provided element between each element.`Last``[a] -> a`YesYesYesReturns the last element of the IterList.`Length``[a] -> int`YesYesYesReturns the number of elements in the IterList.`Map``[a] -> (a -> bool) -> [a]`YesYesYesReturns an IterList with the passed function applied to every element.`Maximum``[a] -> a`YesYesNoReturns the maximum element from the IterList.`MaximumBy``[a] -> (a -> a -> a) -> a`YesYesYesReturns the maximum element from the IterList according to the predicate.`Minimum``[a] -> a`YesYesNoReturns the minimum element from the IterList.`MinimumBy``[a] -> (a -> a -> a) -> a`YesYesYesReturns the minimum element from the IterList according to the predicate.`Nub``[a] -> [a]`YesYesYesReturns the IterList with duplicates removed.`Null``[a] -> bool`YesYesYesReturns true if the IterList is empty; otherwise false.`Sum``[a] -> a`NoYesNoReturns the sum of all elements.`Tail``[a] -> [a]`YesYesYesReturns the IterList without its first element.`Take``[a] -> int -> [a]`YesYesYesReturns an IterList with only the first n elements, where n is specified.`TakeWhile``[a] -> (a -> bool) -> [a]`YesYesYesReturns an IterList with all elements until the predicate fails.---

#### Contributing

[](#contributing)

- Fork the Repository
- Clone your repository
- Run `composer install` to install the composer packages required
- Add functions as a Trait in the `src/Functions` folder
- Be sure to add the `@mixin` PHPDoc comment, hinting that it is a mixin for IterList
- `use` the Trait on each of the Types it is valid for, see `src/Types/Ints.php` and copy if unsure.
- Add tests in `tests/Functions` - copy the layout of an existing one using the TestBuilder if possible.
- Adhere to PHP7.4 (arrow functions etc.) as I'd like to force myself to use the latest version wherever possible!
- Push your branch up to your forked repository and create a Pull Request into mine.
- Once tests pass, it'll be reviewed :)

**There is currently no documentation for HasPHP but keep an eye open as I plan to add this soon.****This will change the contributing guidelines.**

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 85.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

2325d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/cdb14dc132e7a82c6bd002baebad7fbc4c9e0b0d09b4ab50f2f0e8a637a06385?d=identicon)[xcgpseud](/maintainers/xcgpseud)

---

Top Contributors

[![xcgpseud](https://avatars.githubusercontent.com/u/1755473?v=4)](https://github.com/xcgpseud "xcgpseud (72 commits)")[![chrisevans-go](https://avatars.githubusercontent.com/u/65916007?v=4)](https://github.com/chrisevans-go "chrisevans-go (11 commits)")[![DylanMeeus](https://avatars.githubusercontent.com/u/2179051?v=4)](https://github.com/DylanMeeus "DylanMeeus (1 commits)")

### Embed Badge

![Health badge](/badges/xcgpseud-hasphp/health.svg)

```
[![Health](https://phpackages.com/badges/xcgpseud-hasphp/health.svg)](https://phpackages.com/packages/xcgpseud-hasphp)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
