Skip to content

Commit

Permalink
std: Use ElementAtOrDefault in iter::at for non-indexables as well
Browse files Browse the repository at this point in the history
  • Loading branch information
PaddiM8 committed Dec 4, 2024
1 parent 0e3ff0f commit a87350b
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/Std/Iteration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static RuntimeGenerator Append(IEnumerable<RuntimeObject> items, RuntimeO
public static RuntimeObject At(IEnumerable<RuntimeObject> items, RuntimeObject index, RuntimeObject? fallback = null)
{
if (items is not IIndexable<RuntimeObject> indexable)
return items.ElementAt((int)index.As<RuntimeInteger>().Value);
return items.ElementAtOrDefault((int)index.As<RuntimeInteger>().Value) ?? RuntimeNil.Value;

try
{
Expand Down Expand Up @@ -652,11 +652,8 @@ private static IEnumerable<RuntimeObject> Window(IEnumerable<RuntimeObject> valu
}
}

if (buffer.Any())
if (buffer.Count == size)
{
while (buffer.Count < size)
buffer.Enqueue(RuntimeNil.Value);

yield return new RuntimeList(buffer.ToList());
buffer.Clear();
}
Expand Down

0 comments on commit a87350b

Please sign in to comment.