1
// EnumerableExtensions.cs
3
// GNOME Do is the legal property of its developers. Please refer to the
4
// COPYRIGHT file distributed with this source distribution.
6
// This program is free software: you can redistribute it and/or modify
7
// it under the terms of the GNU General Public License as published by
8
// the Free Software Foundation, either version 3 of the License, or
9
// (at your option) any later version.
11
// This program is distributed in the hope that it will be useful,
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
// GNU General Public License for more details.
16
// You should have received a copy of the GNU General Public License
17
// along with this program. If not, see <http://www.gnu.org/licenses/>.
21
using System.Collections;
22
using System.Collections.Generic;
26
public static class EnumerableExtensions
30
/// Performs the specified action on each member of an enumerable.
32
/// <param name="self">
33
/// A <see cref="IEnumerable"/> whose members will have an action performed on them.
35
/// <param name="action">
36
/// A <see cref="Action"/> to perform on each member.
39
/// The original <see cref="IEnumerable"/> for chaining.
41
public static IEnumerable<T> ForEach<T> (this IEnumerable<T> self, Action<T> action)
43
if (self == null) throw new ArgumentNullException ("self");
44
if (action == null) throw new ArgumentNullException ("action");
46
foreach (T x in self) action (x);
51
/// Prepends ("cons") an element to an enumerable.
54
/// If maybeTs is null, a singleton enumerable is returned.
57
/// A <see cref="T"/> to prepend.
60
/// A <see cref="IEnumerable"/> that may be null.
63
/// A <see cref="IEnumerable"/>
65
public static IEnumerable<T> Cons<T> (this T t, IEnumerable<T> maybeTs)
67
if (t == null) throw new ArgumentNullException ("t");
70
if (maybeTs == null) yield break;
71
foreach (T x in maybeTs) yield return x;