some

function some( arr, fv ) --> res

Description

Returns true if fv( v ) returns true for any item in arr.

Parameters

arr

Array table with items that will be checked.

fv

Function that get one item and returns true or false.

Return Values

res

True if any item returns true with function fv, otherwise false.

Code

--ZFUNC-some-v1
local function some( arr, fv ) --> res
   for i, v in ipairs( arr ) do
      if fv( v ) then return true end
   end
   return false
end

return some

Examples

local t = require( "taptest" )
local iseven = require( "iseven" )
local some = require( "some" )

t( some( { 1, 2, 3, 4 }, iseven ), true )
t( some( { 1, 3, 5, 7 }, iseven ), false )

t()