forked from ifrpl/muyo
/
lst.php
99 lines (93 loc) · 1.77 KB
/
lst.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
// Copyright IF Research Sp. z o.o. 2013.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
require_once __DIR__.'/debug.php';
require_once __DIR__.'/misc.php';
if( !function_exists('is_array_list') )
{
/**
* @param mixed $val
* @return bool
*/
function is_array_list($val)
{
if( !is_array($val) )
{
$ret = false;
}
else
{
if( empty($val) )
{
$ret = true; // WARNING: common for both type of arrays
}
else
{
$ret = array_some($val,tuple_get(1,'is_int'));
}
}
return $ret;
}
}
if( !function_exists('list_uniq') )
{
/**
* Warning: Opposed to {@see array_uniq} it doesn't preserve original keys
*
* @param array $list
* @param callable $iterator
*
* @return array
*/
function list_uniq($list, $iterator)
{
return array_values(array_uniq($list,$iterator));
}
}
if( !function_exists('list_filter_key') )
{
/**
* @param array $list
* @param callable $filter
* @return array
*/
function list_filter_key( $list, $filter )
{
return array_values( array_filter_key( $list, $filter ) );
}
}
if( !function_exists('list_filter_key_dg') )
{
/**
* @param callable $filter
* @param callable|array|null $list
* @return callable
*/
function list_filter_key_dg( $filter, $list=null )
{
if( null===$list )
{
$list = tuple_get();
}
elseif( is_array_list($list) )
{
$list = return_dg( $list );
}
else
{
debug_assert_type( $list, 'callable' );
}
debug_assert_type( $filter, 'callable' );
return function()use( $list, $filter )
{
$args = func_get_args();
$list = call_user_func_array( $list, $args );
return list_filter_key(
$list,
$filter
);
};
}
}