Skip to content

rkozlov95/php-pairs

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

php-pairs

github action status

Install

$ composer require hexlet/pairs

Functions for working with Pairs

<?php

use function PhpPairs\Pairs\cons;
use function PhpPairs\Pairs\car;
use function PhpPairs\Pairs\cdr;
use function PhpPairs\Pairs\toString;

Functions for working with Lists

<?php

use function PhpPairs\Lists\length;
use function PhpPairs\Lists\reverse;
use function PhpPairs\Lists\map;
use function PhpPairs\Lists\filter;
use function PhpPairs\Lists\reduce;

Usage examples

<?php

$pair = cons(1, 2);

$one = \PhpPairs\Pairs\car($pair); // $one = 1;
$two = \PhpPairs\Pairs\cdr($pair) // $two = 2;

$list = cons(1, cons(2, cons(3, cons(4, cons(5, cons(6, null))))));
$length = length($list); // $length = 6;

$filter = filter($list, function ($x) {
    return $x % 2 == 0;
});
$result = toString($filter); // $result = "(2, 4, 6)";

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 98.3%
  • Makefile 1.7%