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 MoveNext(Func> processor) { if (!_iterator.MoveNext()) return false; if (await processor(_iterator.Current) is object value) _iterator.Add(value); return true; } public object? Result => _iterator.Result; }