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( "tapered" )
local some = require( "some" )

local iseven = require( "iseven" )

t.ok( some( { 1, 2, 3, 4 }, iseven ) )
t.nok( some( { 1, 3, 5, 7 }, iseven ) )

t.done()