Skip to content

A PHP class that handles the boilerplate for converting an iterable into an array

Notifications You must be signed in to change notification settings

navarr/iterable_to_array

Repository files navigation

IterableToArray::convert

Latest Stable Version Total Downloads Latest Unstable Version License
Tests Code Coverage Mutation score

A simple utility class that handles the boilerplate of converting an iterable into an array.

The goal of this utility is to be an in-place replacement for iterator_to_array whenever one must handle an iterable.

Installation

composer require navarr/iterable-to-array

Usage

<?php

use Navarr\Utils\IterableToArray

// ...

$array = IterableToArray::convert($iterable);

// This replaces:

$array = is_array($iterable) ? $iterable : iterator_to_array($iterable);

This also has (what should be unnecessary) forward compatibility for a scenario where an object passes the iterable type check but is neither an array nor a \Traversable.

About

A PHP class that handles the boilerplate for converting an iterable into an array

Topics

Resources

Stars

Watchers

Forks

Sponsor this project

 

Languages