Eliminating repetitions of subsequent items in a list I would like to convert a list A
A = {1, 12, 3, 3, 3, 8, 5, 5 }

into list B
B = {1, 12, 3, 8, 5 }

As you see, items 3 and 5 are repeated in A, and those repetitions are eliminated in B.
The code I've created to do that is the following:
public IEnumerable&lt;int&gt; FilterRepeatingElements(IEnumerable&lt;int&gt; source) 
{
    return source
        .Select(x =&gt; (IEnumerable&lt;int&gt;)new[] { x })
        .Aggregate((a, b) =&gt; a.Last() != b.First() ? a.Concat(b) : a);
}

It works, but I wonder if there's a better more expressive way to do it using &quot;LINQ&quot;, either with the classic .NET methods or the ones in a library like morelinq.
Thanks!
EDIT
I have found out that my solution has problem with uses case like this:
FilterRepeatingElements(MoreEnumerable.Random()).Take(10)


MoreEnumerable.Random() generates an infinite sequence.
Executing code like this, hangs the execution.
While aepot answer is a good answer and got my upvote it does only work for type int.  Which I know the question for an example uses int in their code but if wanting it to work for all data types will need to change the code a bit.
public static class EnumerableExtensions
{
    public static IEnumerable&lt;TSource&gt; FilterRepeatingElements&lt;TSource&gt;(this IEnumerable&lt;TSource&gt; source, IEqualityComparer&lt;TSource&gt; comparer)
    {
        using (var enumerator = source.GetEnumerator())
        {
            if (enumerator.MoveNext())
            {
                var item = enumerator.Current;
                yield return item;

                while (enumerator.MoveNext())
                {
                    if (!comparer.Equals(item, enumerator.Current))
                    {
                        item = enumerator.Current;
                        yield return item;
                    }
                }
            }
        }
    }

    public static IEnumerable&lt;TSource&gt; FilterRepeatingElements&lt;TSource&gt;(this IEnumerable&lt;TSource&gt; source)
    {
        return FilterRepeatingElements(source, EqualityComparer&lt;TSource&gt;.Default);
    }
}

This would work for any type and takes the same parameters as linq Distinct does since we are doing a &quot;kind of&quot; distinct.
var data = new int[] { 1, 12, 3, 3, 3, 8, 5, 5 };
var postData = data.FilterRepeatingElements().ToArray();

var items = new string[] { &quot;A&quot;, &quot;A&quot;, &quot;B&quot;, &quot;C&quot;, &quot;C&quot;, &quot;D&quot;, &quot;D&quot; };
var postItems = items.FilterRepeatingElements().ToArray();