Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

array ngram type checker #9

Open
leafo opened this issue Feb 8, 2018 · 2 comments
Open

array ngram type checker #9

leafo opened this issue Feb 8, 2018 · 2 comments

Comments

@leafo
Copy link
Owner

leafo commented Feb 8, 2018

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)
@leafo
Copy link
Owner Author

leafo commented Feb 8, 2018

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)

@leafo
Copy link
Owner Author

leafo commented Feb 8, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant