PHPackages                             hassan/one-loop - 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. hassan/one-loop

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

hassan/one-loop
===============

A Laravel/PHP Package for Minimizing Collection/Array Iterations

2.0.0(5mo ago)136MITPHPPHP ^7.2.5|^8.0|^8.1|^8.2|^8.3CI failing

Since Aug 13Pushed 5mo agoCompare

[ Source](https://github.com/dhassanali/one-loop)[ Packagist](https://packagist.org/packages/hassan/one-loop)[ Docs](https://github.com/dhassanali/one-loop)[ RSS](/packages/hassan-one-loop/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (3)Dependencies (3)Versions (4)Used By (0)

One Loop
========

[](#one-loop)

[![Latest Version on Packagist](https://camo.githubusercontent.com/d0045ac6b0a522383ca72140bb107dd20ebb783a1457969587771568ff5e3df2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f68617373616e2f6f6e652d6c6f6f702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/hassan/one-loop)[![Build Status](https://camo.githubusercontent.com/a493abcf8a52ca3e8fab8d04a32fa4c12ff622170bccc365ee93a31cb07b2b36/68747470733a2f2f62616467656e2e6e65742f7472617669732f6468617373616e616c692f6f6e652d6c6f6f702f6d6173746572)](https://travis-ci.org/dhassanali/one-loop)[![License](https://camo.githubusercontent.com/4e5f64af8dbf46d126644c4a367f5cdf246098735d3e17762028b16507a3afe6/68747470733a2f2f62616467656e2e6e65742f7061636b61676973742f6c6963656e73652f68617373616e2f6f6e652d6c6f6f70)](https://packagist.org/packages/hassan/one-loop)[![Coverage Status](https://camo.githubusercontent.com/38c23a9e97258203ff9dd2497b706d295ccb1d394ceba544057a512d10e27931/68747470733a2f2f62616467656e2e6e65742f636f6465636f762f632f6769746875622f6468617373616e616c692f6f6e652d6c6f6f70)](https://codecov.io/github/dhassanali/one-loop)

A Laravel/PHP Package for Minimizing Collection/Array Iterations - **optimized for large datasets (100,000+ records)**.

📊 Performance Benchmarks
------------------------

[](#-performance-benchmarks)

Real-world performance tests show significant improvements with large datasets:

Dataset SizeOperationsStandard PHPOneLoopImprovement500,000Complex (3+ ops)163.03 ms105.84 ms**35% faster** ✅500,000Simple (2 ops)226.32 ms161.79 ms**29% faster** ✅100,000Complex (3+ ops)25.83 ms18.54 ms**28% faster** ✅10,000Any0.98 ms1.84 ms88% slower ⚠️1,000Any0.08 ms0.19 ms137% slower ⚠️### ⚠️ Performance Warning

[](#️-performance-warning)

**This package is optimized for large datasets.** It provides significant performance improvements when:

- Processing **100,000+ records**
- Chaining **2-3+ operations** (filter, map, reject, etc.)
- Running **batch jobs** or **data processing tasks**

For small datasets (&lt; 50,000 records), standard PHP array functions or Laravel Collections will be faster due to lower overhead.

Installation
------------

[](#installation)

Install the package via composer:

```
composer require hassan/one-loop
```

Usage
-----

[](#usage)

### Basic Example

[](#basic-example)

```
$users = App\User::all();

$ids = one_loop($users)->reject(static function ($user) {
    return $user->age < 20;
})
->map(static function ($user) {
    return $user->id;
})
->apply();
```

🆕 New Features in v2.0
----------------------

[](#-new-features-in-v20)

### Early Exit with `limit()` / `take()`

[](#early-exit-with-limit--take)

Stop processing once you have enough results:

```
// Get first 100 active users
$users = one_loop($allUsers)
    ->filter(fn($user) => $user->active)
    ->limit(100)
    ->apply();

// Alias: take()
$users = one_loop($allUsers)
    ->filter(fn($user) => $user->active)
    ->take(100)
    ->apply();
```

### Extract Properties with `pluck()`

[](#extract-properties-with-pluck)

```
// Pluck by property name
$emails = one_loop($users)
    ->pluck('email')
    ->apply();

// Pluck with callback
$fullNames = one_loop($users)
    ->pluck(fn($user) => $user->first_name . ' ' . $user->last_name)
    ->apply();
```

### Remove Duplicates with `unique()`

[](#remove-duplicates-with-unique)

```
// Unique values
$uniqueDepartments = one_loop($employees)
    ->pluck('department')
    ->unique()
    ->apply();

// Unique by key
$uniqueUsers = one_loop($users)
    ->unique('email')
    ->apply();
```

### Group Items with `groupBy()`

[](#group-items-with-groupby)

```
// Group by property
$byDepartment = one_loop($employees)
    ->groupBy('department')
    ->apply();

// Group by callback
$byAgeGroup = one_loop($users)
    ->groupBy(function($user) {
        if ($user->age < 30) return 'young';
        if ($user->age < 50) return 'middle';
        return 'senior';
    })
    ->apply();
```

### Conditional Operations with `when()`

[](#conditional-operations-with-when)

```
$shouldFilterActive = true;

$result = one_loop($users)
    ->when($shouldFilterActive, function($loop) {
        $loop->filter(fn($user) => $user->active);
    })
    ->map(fn($user) => $user->id)
    ->apply();
```

### Laravel Collection Integration

[](#laravel-collection-integration)

OneLoop automatically integrates with Laravel Collections:

```
use Illuminate\Support\Collection;

// Use on any Collection
$result = User::all()
    ->oneLoop()
    ->filter(fn($user) => $user->active)
    ->map(fn($user) => $user->id)
    ->apply();
```

🎓 Available Methods
-------------------

[](#-available-methods)

### Filtering

[](#filtering)

- `filter(callable $callback)` - Keep items that match condition
- `reject(callable $callback)` - Remove items that match condition

### Transformation

[](#transformation)

- `map(callable $callback)` - Transform each item
- `pluck(string|callable $value)` - Extract specific property

### Uniqueness &amp; Grouping

[](#uniqueness--grouping)

- `unique(?string|callable $key = null)` - Remove duplicates
- `groupBy(string|callable $groupBy)` - Group by key or callback

### Limiting

[](#limiting)

- `limit(int $limit)` - Limit results (early exit)
- `take(int $count)` - Alias for limit()

### Conditional

[](#conditional)

- `when(bool $condition, callable $callback, ?callable $default = null)` - Conditional operations

### Execution

[](#execution)

- `apply()` - Execute all queued operations and return results

📊 When to Use OneLoop
---------------------

[](#-when-to-use-oneloop)

### ✅ Perfect For:

[](#-perfect-for)

- **Large datasets** (100K+ records)
- **Batch processing** jobs
- **ETL operations**
- **Data migrations**
- **Complex filtering** with 2-3+ operations
- **Report generation**
- **Product catalog filtering** (e-commerce)
- **Customer segmentation** (marketing)

### ❌ Not Ideal For:

[](#-not-ideal-for)

- Small datasets (&lt; 50K records)
- Single operation (just one filter or map)
- Real-time web requests with small result sets
- When microseconds matter with tiny datasets

🎯 Real-World Example
--------------------

[](#-real-world-example)

```
// E-commerce: Process large product catalog
$products = Product::all()  // 500,000 products
    ->oneLoop()
    ->filter(fn($p) => $p->active)
    ->reject(fn($p) => $p->stock when($categoryFilter, fn($loop) =>
        $loop->filter(fn($p) => in_array($p->category_id, $categoryFilter))
    )
    ->map(fn($p) => [
        'id' => $p->id,
        'name' => $p->name,
        'price' => $p->price * 0.9  // 10% discount
    ])
    ->limit(1000)
    ->apply();

// Result: 35% faster than standard operations!
```

🧪 Testing
---------

[](#-testing)

```
composer test
```

📝 Changelog
-----------

[](#-changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

🤝 Contributing
--------------

[](#-contributing)

Contributions are welcome! Please feel free to submit a Pull Request.

🔒 Security
----------

[](#-security)

If you discover any security related issues, please email  instead of using the issue tracker.

📜 License
---------

[](#-license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

🙏 Credits
---------

[](#-credits)

- [Hassan Ali](https://github.com/dhassanali)
- [All Contributors](../../contributors)

###  Health Score

44

—

FairBetter than 92% of packages

Maintenance70

Regular maintenance activity

Popularity11

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity75

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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

Every ~1145 days

Total

3

Last Release

175d ago

Major Versions

0.1.1 → 1.0.02019-08-13

1.0.0 → 2.0.02025-11-20

PHP version history (2 changes)0.1.1PHP ^7.1

2.0.0PHP ^7.2.5|^8.0|^8.1|^8.2|^8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/af2f10ca91e0fb01d06fb9c648bb04ecf3205bcc1b5570974e14320a85f9178e?d=identicon)[hassan\_ali](/maintainers/hassan_ali)

---

Top Contributors

[![dhassanali](https://avatars.githubusercontent.com/u/12805108?v=4)](https://github.com/dhassanali "dhassanali (12 commits)")

---

Tags

laravellaravel-collectionslaravel-packagephpperformancecollectionoptimizationcollectlaravel-collectionHassan one-loop

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/hassan-one-loop/health.svg)

```
[![Health](https://phpackages.com/badges/hassan-one-loop/health.svg)](https://phpackages.com/packages/hassan-one-loop)
```

###  Alternatives

[webpatser/laravel-uuid

Laravel integration for webpatser/uuid - High-performance drop-in UUID replacements (15% faster than Ramsey). Provides Str macros, HasUuids trait, facades, and casts. RFC 4122/9562 compliant.

1.8k17.3M129](/packages/webpatser-laravel-uuid)[lorisleiva/lody

Load files and classes as lazy collections in Laravel.

956.6M9](/packages/lorisleiva-lody)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)[nilportugues/php_backslasher

Adds all PHP internal functions to its namespace by adding backslash to them. Improves the application's performance when OPCache is on.

889.3k18](/packages/nilportugues-php-backslasher)[krisawzm/critical-css

A Laravel package for generating and using inline critical-path CSS.

4714.2k2](/packages/krisawzm-critical-css)

PHPackages © 2026

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