using System;
using System.Collections.Generic;
namespace Swan {
///
/// Functional programming extension methods.
///
public static class FunctionalExtensions {
///
/// Whens the specified condition.
///
/// The type of IEnumerable.
/// The list.
/// The condition.
/// The function.
///
/// The IEnumerable.
///
///
/// this
/// or
/// condition
/// or
/// fn.
///
public static IEnumerable When(this IEnumerable list, Func condition, Func, IEnumerable> fn) {
if(list == null) {
throw new ArgumentNullException(nameof(list));
}
if(condition == null) {
throw new ArgumentNullException(nameof(condition));
}
if(fn == null) {
throw new ArgumentNullException(nameof(fn));
}
return condition() ? fn(list) : list;
}
}
}