MCAEmotiv.Interop.EEGDataEntryExtensions.SectionByStimulus C# (CSharp) Method

SectionByStimulus() public static method

Groups entries using the sequences formed by their relative timestamps
public static SectionByStimulus ( this entries ) : IEnumerable>
entries this
return IEnumerable>
        public static IEnumerable<IArrayView<EEGDataEntry>> SectionByStimulus(this IEnumerable<EEGDataEntry> entries)
        {
            if (entries.IsEmpty())
                yield break;

            var section = new List<EEGDataEntry>() { entries.First() };
            foreach (var entry in entries.Skip(1))
            {
                if (entry.RelativeTimeStamp >= section.LastItem().RelativeTimeStamp)
                    section.Add(entry);
                else
                {
                    yield return section.AsIArray();
                    section = new List<EEGDataEntry>() { entry };
                }
            }

            yield return section.AsIArray(); // return the last section
        }