pike.git / lib / modules / Array.pmod

version» Context lines:

pike.git/lib/modules/Array.pmod:748:   }      //! Returns 1 if all of the elements in @[a] fulfills the requirement   //! @[predicate]( @[a][@i{i@}], @@@[extra_args] ), otherwise 0. The   //! predicate should return non-zero for an element that meets the   //! requirements and zero for those that do not.   //! @example   //! Array.all( ({ 2, 4, 6, 8 }), `<, 17 )   //! @seealso   //! @[any], @[has_value] - int(0..1) all( array a, function predicate, mixed ... extra_args ) + int(0..1) all( array a, function(mixed,mixed ...:int(0..1)) predicate, +  mixed ... extra_args )   {    foreach( a, mixed elem )    if( !predicate( elem, @extra_args ) )    return 0;    return 1;   }      //! Returns 1 if any of the elements in @[a] fulfills the requirement   //! @[predicate]( @[a][@i{i@}], @@@[extra_args] ), otherwise 0. The   //! predicate should return non-zero for an element that meets the   //! requirements and zero for those that do not.   //! @example   //! Array.any( ({ 2, 4, 6, 8 }), `>, 5 )   //! @seealso   //! @[all], @[has_value] - int(0..1) any( array a, function predicate, mixed ... extra_args ) + int(0..1) any( array a, function(mixed,mixed ...:int(0..1)) predicate, +  mixed ... extra_args )   {    foreach( a, mixed elem )    if( predicate( elem, @extra_args ) )    return 1;    return 0;   }      //! Splits an array in two, according to an arbitration function   //! @[arbiter]. The elements in @[a] who return non-zero for the   //! expression @[arbiter]( @[a][@i{i@}], @extra_args ) end up in   //! the first sub-array, the others in the second. The order is   //! preserved from the original array.   //! @example   //! Array.partition( enumerate( 9 ), lambda(int n) { return n>3 && n<7; } );   //! > ({ ({ 4, 5, 6 }), ({ 0, 1, 2, 3, 7, 8 }) })   //! @seealso   //! @[filter], @[`/], @[`%] - array(array) partition( array a, function arbiter, mixed ... extra_args ) + array(array) partition( array a, function(mixed,mixed...:int(0..1)) arbiter, +  mixed ... extra_args )   {    array first = ({}), second = ({});    foreach( a, mixed elem )    if( arbiter( elem, @extra_args ) )    first += ({ elem });    else    second += ({ elem });    return ({ first, second });   }