Open pardouin opened 2 months ago
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])
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 :-)
Not sure how to contribute exactly but I just had this cool idea inspired by
fmap
/map
. Typically when usinggroupsof
orwindowsof
with strings, it's pretty common that you actually want to yield strings and not tuples of chars. So for examplefgroupsof(3, "ABCDEFGH")
would yield"ABC"
,"DEF"
,"GH"
.