﻿using System;
using System.Collections.Generic;

namespace Styx
{
    internal static class EnumerableExtensions
    {
        public static IEnumerable<T> Do<T>(this IEnumerable<T> enumerable, Action<T> onNext)
        {
            if (enumerable == null)
                throw new ArgumentNullException("enumerable");
            if (onNext == null)
                throw new ArgumentNullException("onNext");

            foreach (var item in enumerable)
            {
                onNext(item);
                yield return item;
            }
        }

        public static ISet<T> ToSet<T>(this IEnumerable<T> enumerable)
        {
            if (enumerable == null)
                throw new ArgumentNullException("enumerable");

            return new HashSet<T>(enumerable);
        }
    }
}