feat: Added extension method for peeking queues

This commit is contained in:
Chris Cameron
2019-04-23 09:57:28 -04:00
parent 995a57f8e4
commit 22978e90c4
2 changed files with 24 additions and 0 deletions

View File

@@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## [Unreleased]
### Added
- Added extension method for peeking queues
## [9.3.0] - 2019-04-16
### Added
- Added SPlusUtils with ConvertToInt method taking LowWord/HighWord ushorts

View File

@@ -43,5 +43,26 @@ namespace ICD.Common.Utils.Extensions
item = extends.Dequeue();
return true;
}
/// <summary>
/// Peeks the next item in the queue. Returns false if the queue is empty.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="extends"></param>
/// <param name="item"></param>
/// <returns></returns>
public static bool Peek<T>(this Queue<T> extends, out T item)
{
if (extends == null)
throw new ArgumentNullException("extends");
item = default(T);
if (extends.Count == 0)
return false;
item = extends.Peek();
return true;
}
}
}