You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Connected.Framework/Connected.Collections/Iterator.cs

34 lines
764 B

2 years ago
using Connected.Collections.Iterators;
namespace Connected.Collections;
public class Iterator
{
private IIterator _iterator;
public Iterator(object value)
{
if (value is null)
throw new ArgumentException(nameof(value));
if (DictionaryIterator.CanHandle(value))
_iterator = new DictionaryIterator(value);
else if (ListIterator.CanHandle(value))
_iterator = new ListIterator(value);
else if (ArrayIterator.CanHandle(value))
_iterator = new ArrayIterator(value);
}
public async Task<bool> MoveNext(Func<object, Task<object>> processor)
{
if (!_iterator.MoveNext())
return false;
if (await processor(_iterator.Current) is object value)
_iterator.Add(value);
return true;
}
public object? Result => _iterator.Result;
}