This shows you the differences between two versions of the page.
Both sides previous revision Previous revision | Next revision Both sides next revision | ||
api:transforms [2017/10/19 19:53] payonel [Methods] |
api:transforms [2017/10/19 20:42] payonel [Methods] |
||
---|---|---|---|
Line 15: | Line 15: | ||
Behaves similarly to `string.sub`. Returns a sub table of `tbl` from `first` to `last`. | Behaves similarly to `string.sub`. Returns a sub table of `tbl` from `first` to `last`. | ||
- | * `transforms.find(tbl: table, predicate: function or table, first: number or nil, last: number or nil): number, number` | + | * `transforms.first(tbl: table, predicate: function or table, first: number or nil, last: number or nil): number, number` |
Returns the first index in `tbl` (between indexes `first` and `last`, inclusively) where `predicate` is satisfied. The 2nd return is also the ending index of the match. General examples will have the same two values, i.e. a match of 1. Technically, the `predicate` can return a 2nd return value to indicate where the pattern matching completed. | Returns the first index in `tbl` (between indexes `first` and `last`, inclusively) where `predicate` is satisfied. The 2nd return is also the ending index of the match. General examples will have the same two values, i.e. a match of 1. Technically, the `predicate` can return a 2nd return value to indicate where the pattern matching completed. | ||
Line 30: | Line 30: | ||
local tx = require("transforms") | local tx = require("transforms") | ||
- | print( tx.find ( { 1, 1, 3, 2, 4, 7 }, function(e, i, tbl) | + | print( tx.first ( { 1, 1, 3, 2, 4, 7 }, function(e, i, tbl) |
local evens = 0 | local evens = 0 | ||
for i=i,#tbl do | for i=i,#tbl do |