public T this[int index, T defaultValue] { get { if ((uint)index < (uint)_count) { bool fail; var r = _list.TryGet(_start + index, out fail); return(fail ? defaultValue : r); } return(defaultValue); } }
static LNode Single(IListSource <LNode> e) { LNode node = e.TryGet(0, null); if (node == null) { throw new InvalidOperationException(Localize.Localized("ParseSingle: result was empty.")); } if (e.TryGet(1, null) != null) // don't call Count because e is typically Buffered() { throw new InvalidOperationException(Localize.Localized("ParseSingle: multiple parse results.")); } return(node); }
/// <summary>Uses list.TryGet(index) to find out if the specified index is valid.</summary> /// <returns>true if the specified index is valid, false if not.</returns> public static bool HasIndex <T>(this IListSource <T> list, int index) { bool fail; list.TryGet(index, out fail); return(!fail); }
public TResult TryGet(int index, ref bool fail) { T t = _list.TryGet(index, ref fail); if (!fail) { return(_selector(t)); } return(default(TResult)); }
public sealed override TResult TryGet(int index, out bool fail) { T t = _list.TryGet(index, out fail); if (!fail) { return(_selector(t)); } return(default(TResult)); }
public static T FirstOrDefault <T>(this IListSource <T> list, T defaultValue) { bool fail; var result = list.TryGet(0, out fail); if (fail) { return(defaultValue); } return(result); }
/// <summary>Tries to get a value from the list at the specified index.</summary> /// <param name="index">The index to access. Valid indexes are between 0 and Count-1.</param> /// <returns>The retrieved value wrapped in <see cref="Maybe{T}"/>, if any.</returns> public static Maybe <T> TryGet <T>(this IListSource <T> list, int index) { bool fail; T result = list.TryGet(index, out fail); if (fail) { return(Maybe <T> .NoValue); } return(new Maybe <T>(result)); }
/// <summary>Tries to get a value from the list at the specified index.</summary> /// <param name="index">The index to access. Valid indexes are between 0 and Count-1.</param> /// <param name="value">A variable that will be changed to the retrieved value. If the index is not valid, this variable is left unmodified.</param> /// <returns>True on success, or false if the index was not valid.</returns> public static bool TryGet <T>(this IListSource <T> list, int index, ref T value) { bool fail; T result = list.TryGet(index, out fail); if (fail) { return(false); } value = result; return(true); }
protected bool AdvanceAfterNextNewline(ref int index) { for (;;) { bool fail; char c = _source.TryGet(index, out fail); if (fail) { return(false); } if (c == '\r' || c == '\n') { index++; if (c == '\r' && _source.TryGet(index, out fail) == '\n') { index++; } return(true); } index++; } }
/// <summary>Tries to get a value from the list at the specified index.</summary> /// <param name="index">The index to access. Valid indexes are between 0 and Count-1.</param> /// <param name="defaultValue">A value to return if the index is not valid.</param> /// <returns>The retrieved value, or defaultValue if the index provided was not valid.</returns> public static T TryGet <T>(this IListSource <T> list, int index, T defaultValue) { bool fail; T result = list.TryGet(index, out fail); if (fail) { return(defaultValue); } else { return(result); } }
public Iterator <T> GetIterator() { int i = _start, stop = i + _length; IListSource <T> list = _obj; return(delegate(ref bool ended) { if (i < stop) { return list.TryGet(i++, ref ended); } ended = true; return default(T); }); }
/// <summary>Returns a slice without the initial elements of the list that meet the specified /// criteria. The word "now" is added to the name because unlike Enumerable.SkipWhile, this /// method scans the list immediately.</summary> /// <remarks>Example: new[] { 24, 28, 2, 12, 11 }.SkipNowWhile(n => n > 10) returns a slice /// (not a copy) of the last 2 elements.</remarks> public static Slice_ <T> SkipNowWhile <T>(this IListSource <T> list, Func <T, bool> predicate) { Maybe <T> value; for (int i = 0;; i++) { if (!(value = list.TryGet(i)).HasValue) { return(new Slice_ <T>()); } else if (!predicate(value.Value)) { return(new Slice_ <T>(list, i)); } } }
public T TryGet(int index, ref bool fail) { return(_list.TryGet(_list.Count - 1 - index, ref fail)); }
public sealed override T TryGet(int index, out bool fail) { return(_list.TryGet(_list.Count - 1 - index, out fail)); }
protected sealed override Token LT(int i) { bool fail; return(_tokens.TryGet(InputPosition + i, out fail)); }
public override TOut TryGet(int index, out bool fail) { return(_list.TryGet(index, out fail)); }
public static T FirstOrDefault <T>(this IListSource <T> list) { bool _; return(list.TryGet(0, out _)); }
static LNode Single(IListSource<LNode> e) { LNode node = e.TryGet(0, null); if (node == null) throw new InvalidOperationException(Localize.Localized("ParseSingle: result was empty.")); if (e.TryGet(1, null) != null) // don't call Count because e is typically Buffered() throw new InvalidOperationException(Localize.Localized("ParseSingle: multiple parse results.")); return node; }
protected override Token LT(int i) { return(_tokens.TryGet(InputPosition + i, default(Token))); }
/// <inheritdoc/> public T TryGet(int index, ref bool fail) { return(_list.TryGet(_offset + index, ref fail)); }