array ngram type checker
leafo opened this issue · comments
If you have a flat array of items:
{1,2,2,3,4,5}
And you want to match for every n items starting from every position that yields n items. This will add 1 to every that comes after 2:
type.array_ngram(2, types.number / function(n) return n + 1 end)
The above syntax won't work, since we need a type that represents the tuple together. Additionally, we need a default case to let check_value
match on. Maybe it will split each ngram into arrays that you then have to check?
types.array_ngram(2, types.shape { 2, types.number / function(n) return n + 1 end } + types.any)
The usecase for this was a way to optimize generated moonscript that has
--- some other code....
local hello
hello = function() end
-- some other code....
The pair of statements would represent the ngram in the array