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 String.sliding / chunksOf #142

Open
Dean177 opened this issue May 22, 2020 · 0 comments
Open

Add String.sliding / chunksOf #142

Dean177 opened this issue May 22, 2020 · 0 comments
Labels
good first issue Good for newcomers help wanted Extra attention is needed

Comments

@Dean177
Copy link
Collaborator

Dean177 commented May 22, 2020

Array has the sliding and chunksOf functions:

val sliding : ?step:int -> 'a t -> size:int -> 'a t t
   (** Provides a sliding 'window' of sub-arrays over an array.

     The first sub-array starts at index [0] of the array and takes the first [size] elements.

     The sub-array then advances the index [step] (which defaults to 1) positions before taking the next [size] elements.

     The sub-arrays are guaranteed to always be of length [size] and iteration stops once a sub-array would extend beyond the end of the array.

     {[Array.sliding [|1;2;3;4;5|] ~size:1 = [|[|1|]; [|2|]; [|3|]; [|4|]; [|5|]|] ]}

     {[Array.sliding [|1;2;3;4;5|] ~size:2 = [|[|1;2|]; [|2;3|]; [|3;4|]; [|4;5|]|] ]}

     {[Array.sliding [|1;2;3;4;5|] ~size:3 = [|[|1;2;3|]; [|2;3;4|]; [|3;4;5|]|] ]}

     {[Array.sliding [|1;2;3;4;5|] ~size:2 ~step:2 = [|[|1;2|]; [|3;4|]|] ]}

     {[Array.sliding [|1;2;3;4;5|] ~size:1 ~step:3 = [|[|1|]; [|4|]|] ]}
   *)

let chunksOf t ~size = sliding t ~step:size ~size

These would be good additions to the String module too

@Dean177 Dean177 added help wanted Extra attention is needed good first issue Good for newcomers labels May 22, 2020
@pbiggar pbiggar added this to the 0.2.0 milestone Oct 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants