@@ -1,6 +1,7 @@
11package list
22
33import (
4+ "slices"
45 "strings"
56
67 "github.com/charmbracelet/bubbles/v2/key"
@@ -201,7 +202,7 @@ func (l *list[T]) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
201202 return l, nil
202203 case anim.StepMsg:
203204 var cmds []tea.Cmd
204โ for _, item := range l.items.Slice() {
205+ for _, item := range slices.Collect(l.items.Seq()) {
205206 if i, ok := any(item).(HasAnim); ok && i.Spinning() {
206207 updated, cmd := i.Update(msg)
207208 cmds = append(cmds, cmd)
@@ -288,7 +289,7 @@ func (l *list[T]) viewPosition() (int, int) {
288289
289290func (l *list[T]) recalculateItemPositions() {
290291 currentContentHeight := 0
291โ for _, item := range l.items.Slice() {
292+ for _, item := range slices.Collect(l.items.Seq()) {
292293 rItem, ok := l.renderedItems.Get(item.ID())
293294 if !ok {
294295 continue
@@ -561,7 +562,7 @@ func (l *list[T]) focusSelectedItem() tea.Cmd {
561562 return nil
562563 }
563564 var cmds []tea.Cmd
564โ for _, item := range l.items.Slice() {
565+ for _, item := range slices.Collect(l.items.Seq()) {
565566 if f, ok := any(item).(layout.Focusable); ok {
566567 if item.ID() == l.selectedItem && !f.IsFocused() {
567568 cmds = append(cmds, f.Focus())
@@ -580,7 +581,7 @@ func (l *list[T]) blurSelectedItem() tea.Cmd {
580581 return nil
581582 }
582583 var cmds []tea.Cmd
583โ for _, item := range l.items.Slice() {
584+ for _, item := range slices.Collect(l.items.Seq()) {
584585 if f, ok := any(item).(layout.Focusable); ok {
585586 if item.ID() == l.selectedItem && f.IsFocused() {
586587 cmds = append(cmds, f.Blur())
@@ -655,7 +656,7 @@ func (l *list[T]) AppendItem(item T) tea.Cmd {
655656
656657 l.items.Append(item)
657658 l.indexMap = csync.NewMap[string, int]()
658โ for inx, item := range l.items.Slice() {
659+ for inx, item := range slices.Collect(l.items.Seq()) {
659660 l.indexMap.Set(item.ID(), inx)
660661 }
661662 if l.width > 0 && l.height > 0 {
@@ -702,7 +703,7 @@ func (l *list[T]) DeleteItem(id string) tea.Cmd {
702703 }
703704 l.items.Delete(inx)
704705 l.renderedItems.Del(id)
705โ for inx, item := range l.items.Slice() {
706+ for inx, item := range slices.Collect(l.items.Seq()) {
706707 l.indexMap.Set(item.ID(), inx)
707708 }
708709
@@ -767,7 +768,7 @@ func (l *list[T]) IsFocused() bool {
767768
768769// Items implements List.
769770func (l *list[T]) Items() []T {
770โ return l.items.Slice()
771+ return slices.Collect(l.items.Seq())
771772}
772773
773774func (l *list[T]) incrementOffset(n int) {
@@ -822,7 +823,7 @@ func (l *list[T]) PrependItem(item T) tea.Cmd {
822823 }
823824 l.items.Prepend(item)
824825 l.indexMap = csync.NewMap[string, int]()
825โ for inx, item := range l.items.Slice() {
826+ for inx, item := range slices.Collect(l.items.Seq()) {
826827 l.indexMap.Set(item.ID(), inx)
827828 }
828829 if l.width > 0 && l.height > 0 {
@@ -926,7 +927,7 @@ func (l *list[T]) SelectedItem() *T {
926927func (l *list[T]) SetItems(items []T) tea.Cmd {
927928 l.items.SetSlice(items)
928929 var cmds []tea.Cmd
929โ for inx, item := range l.items.Slice() {
930+ for inx, item := range slices.Collect(l.items.Seq()) {
930931 if i, ok := any(item).(Indexable); ok {
931932 i.SetIndex(inx)
932933 }
@@ -949,7 +950,7 @@ func (l *list[T]) reset(selectedItem string) tea.Cmd {
949950 l.selectedItem = selectedItem
950951 l.indexMap = csync.NewMap[string, int]()
951952 l.renderedItems = csync.NewMap[string, renderedItem]()
952โ for inx, item := range l.items.Slice() {
953+ for inx, item := range slices.Collect(l.items.Seq()) {
953954 l.indexMap.Set(item.ID(), inx)
954955 if l.width > 0 && l.height > 0 {
955956 cmds = append(cmds, item.SetSize(l.width, l.height))