/// <summary>現在位置より前方の、条件を満たす位置へ移動する。</summary> /// <typeparam name="T">要素の型</typeparam> /// <param name="scroller">対象インスタンス</param> /// <param name="predicate">条件</param> public static IElementScroller <T> Previous <T>(this IElementScroller <T> scroller, Predicate <T> predicate) { var cnt = scroller.previousSequence() .Select((v, i) => new { Value = v, Index = i }) .First(x => predicate(x.Value)) .Index + 1; return(scroller.Previous(cnt)); }
/// <summary>現在位置から前方へ指定した距離だけ移動可能な場合は移動する。</summary> /// <typeparam name="T">要素の型</typeparam> /// <param name="scroller">対象インスタンス</param> /// <param name="count">距離</param> /// <returns>結果</returns> public static ResultWithValue <IElementScroller <T> > MaybePrevious <T>(this IElementScroller <T> scroller, int count) { if (scroller.HasPrevious(count)) { return(new ResultWithValue <IElementScroller <T> >(scroller.Previous(count))); } else { return(new ResultWithValue <IElementScroller <T> >(false, scroller)); } }
/// <summary>現在位置より前方に条件を満たす要素が存在した場合はその位置へ移動する。</summary> /// <typeparam name="T">要素の型</typeparam> /// <param name="scroller">対象インスタンス</param> /// <param name="predicate">条件</param> /// <returns>結果</returns> public static ResultWithValue <IElementScroller <T> > MaybePrevious <T>(this IElementScroller <T> scroller, Predicate <T> predicate) { if (scroller.HasPrevious(predicate)) { return(new ResultWithValue <IElementScroller <T> >(scroller.Previous(predicate))); } else { return(new ResultWithValue <IElementScroller <T> >(false, scroller)); } }
/// <summary>前の位置へ移動する。</summary> /// <typeparam name="T">要素の型</typeparam> /// <param name="scroller">対象インスタンス</param> public static IElementScroller <T> Previous <T>(this IElementScroller <T> scroller) { return(scroller.Previous(1)); }