matchesf

function matchesf( pattern ) --> func

Description

Creates a function that takes one string parameter and checks if the pattern matches.

Parameters

pattern

Lua pattern to check the string.

Return Values

func

A new function that takes one parameter and returns true or false.

Code

--ZFUNC-matchesf-v1
local function matchesf( pattern ) --> func
   return function ( str )
      local i = string.find( str, pattern )
      return i ~= nil
   end
end

return matchesf

Examples

local t = require( "taptest" )
local matchesf = require( "matchesf" )

func = matchesf( "ab" )

t( func( "abba" ), true )
t( func( "bbaa" ), false )

t()