Open
Description
A task I occasionally reach for is the ability to iterate through a list in a sliding window to get successive pairs of neighboring elements.
Would we consider adding a windows
function?
windows : List a -> List ( a, a )
windows l =
case l of
x :: y :: rest ->
( x, y ) :: windows2 (y :: rest)
_ ->
[]
Since it may be desirable to have windows of larger sizes, we could name this function windows2
and add functions windows3
, windows4
, etc.
This is similar to Ruby's each_slice
function or Rust's windows
, but returning tuples instead of lists.
P.S. Feel free to include feedback on code style, I'm still fairly new to Elm.
Metadata
Metadata
Assignees
Labels
No labels