Fusonic\Linq\Linq::from PHP Method

from() public static method

This is the recommended way for getting a new Linq instance.
public static from ( array | Iterator | IteratorAggregat\IteratorAggregate $dataSource ) : Linq
$dataSource array | Iterator | IteratorAggregat\IteratorAggregate A Traversable sequence as data source.
return Linq
    public static function from($dataSource)
    {
        return new Linq($dataSource);
    }

Usage Example

Example #1
0
 public function testChunk_ReturnsChunkedElementsAccordingToChunksize()
 {
     $groups = Linq::from([])->chunk(2);
     $this->assertEquals(0, $groups->count());
     $groups = Linq::from(["a"])->chunk(2);
     $this->assertEquals(1, $groups->count());
     $this->assertEquals(1, $groups->ElementAt(0)->count());
     $this->assertEquals("a", $groups->ElementAt(0)->ElementAt(0));
     $groups = Linq::from(["a", "b", "c", "d", "e"])->chunk(2);
     $this->assertEquals(3, $groups->count());
     $this->assertEquals(2, $groups->ElementAt(0)->count());
     $this->assertEquals("a", $groups->ElementAt(0)->ElementAt(0));
     $this->assertEquals("b", $groups->ElementAt(0)->ElementAt(1));
     $this->assertEquals(2, $groups->ElementAt(1)->count());
     $this->assertEquals("c", $groups->ElementAt(1)->ElementAt(0));
     $this->assertEquals("d", $groups->ElementAt(1)->ElementAt(1));
     $this->assertEquals(1, $groups->ElementAt(2)->count());
     $this->assertEquals("e", $groups->ElementAt(2)->ElementAt(0));
     $groups = Linq::from(["a", "b", "c", "d", "e"])->chunk(3);
     $this->assertEquals(2, $groups->count());
     $groups = Linq::from(["a", "b", "c", "d", "e"])->chunk(4);
     $this->assertEquals(2, $groups->count());
     $groups = Linq::from(["a", "b", "c", "d", "e"])->chunk(5);
     $this->assertEquals(1, $groups->count());
     $groups = Linq::from(["a", "b", "c", "d", "e"])->chunk(117);
     $this->assertEquals(1, $groups->count());
 }
All Usage Examples Of Fusonic\Linq\Linq::from