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

Add Built-Ins fgroupsof and fwindowsof #844

Open
pardouin opened this issue Jun 26, 2024 · 2 comments
Open

Add Built-Ins fgroupsof and fwindowsof #844

pardouin opened this issue Jun 26, 2024 · 2 comments
Labels

Comments

@pardouin
Copy link
Contributor

Not sure how to contribute exactly but I just had this cool idea inspired by fmap/map.
Typically when using groupsof or windowsof with strings, it's pretty common that you actually want to yield strings and not tuples of chars.
So for example fgroupsof(3, "ABCDEFGH") would yield "ABC", "DEF", "GH".

@evhub evhub added the feature label Jun 27, 2024
@evhub
Copy link
Owner

evhub commented Jun 27, 2024

Hmmm... this isn't really a Functor operation, so the name fgroupsof doesn't make a ton of sense, but I do see the use case.

If you just want a simple implementation for now, these should work pretty well:

def fgroupsof(n, obj) =
    range(0, len(obj), n) |> map$(start -> obj[start:start+n])

def fwindowsof(n, obj) =
    range(0, len(obj) - n + 1) |> map$(start -> obj[start:start+n])

@pardouin
Copy link
Contributor Author

Thanks for your answer, the names were indeed poorly chosen.
I know how to implement these, just wanted to know if the release of a built-in was an option.
Either new dedicated functions, or maybe an optionnal kwarg to preserve the type for the already existing functions?
It's not very important, just an idea :-)

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

No branches or pull requests

2 participants