Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
api:transforms [2017/10/20 00:58]
payonel [Transforms API]
api:transforms [2017/10/20 01:11] (current)
payonel [Transforms API]
Line 19: Line 19:
   *  `predicate(element:​ value, index: number, tbl: table): number, number`   *  `predicate(element:​ value, index: number, tbl: table): number, number`
  
-  This predicate is called in sequence on each index in `tbl`. `element` is the value at `tbl[index]`. Generally, predicate methods ignore `index` and `tbl`, and only process `element`. But some predicates may need to check values in `tbl` before or after `index`.+  This predicate is called in sequence on each index in `tbl`. `element` is the value at `tbl[index]`. Generally, predicate methods ignore `index` and `tbl`, and only process `element`. But some predicates may need to check values in `tbl` before or after `index`. **Important** to note that the `tbl` passed to the `predicate` is actually a _**view**_ of the original table passed to the transforms api. This _**view**_ is not a natural sequence but instead only returns values from `tbl` within the [`first`, `last`] range.
  
   In other words, the predicate handles a "set of elements"​ and returns parameters indicating the satisfied condition.   In other words, the predicate handles a "set of elements"​ and returns parameters indicating the satisfied condition.
Line 28: Line 28:
  
     A) The single `element` passed to the predicate. This is the same value at `tbl[index]`     A) The single `element` passed to the predicate. This is the same value at `tbl[index]`
 +
     or     or
 +
     B) The sequence of elements starting at `index` in `tbl`. The predicate may iterate from `index` for as many elements it needs to check, until `#tbl`     B) The sequence of elements starting at `index` in `tbl`. The predicate may iterate from `index` for as many elements it needs to check, until `#tbl`
  
     * **Return Parameters**     * **Return Parameters**
 +
     Possible values for the return parameters     Possible values for the return parameters
     1     1
Line 43: Line 46:
     Some transform methods may specify alternative predicate types that can be used, such as tables or strings. These predicate usages are specific to those methods and defined within the method details here.     Some transform methods may specify alternative predicate types that can be used, such as tables or strings. These predicate usages are specific to those methods and defined within the method details here.
  
 +==== Methods ====
  
 * `transforms.sub(tbl:​ table, first: number, last: number or nil): table` * `transforms.sub(tbl:​ table, first: number, last: number or nil): table`