/// <summary>述語の処理により現在の位置が移動した場合、処理前の位置へ戻す。</summary>
        /// <typeparam name="T">要素の型</typeparam>
        /// <param name="scroller">対象インスタンス</param>
        /// <param name="action">処理</param>
        public static IElementScroller <T> Restore <T>(this IElementScroller <T> scroller, Action <IElementScroller <T> > action)
        {
            var b = scroller.Current;

            action(scroller);
            scroller.MoveTo(b);
            return(scroller);
        }
 /// <summary>シーケンス内に指定した要素が存在する場合、その位置へ移動する。</summary>
 /// <typeparam name="T">要素の型</typeparam>
 /// <param name="scroller">対象インスタンス</param>
 /// <param name="element">要素</param>
 /// <returns>結果</returns>
 public static ResultWithValue <IElementScroller <T> > TryMoveTo <T>(this IElementScroller <T> scroller, T element)
 {
     if (scroller.GetSequence().Contains(element))
     {
         return(new ResultWithValue <IElementScroller <T> >(scroller.MoveTo(element)));
     }
     else
     {
         return(new ResultWithValue <IElementScroller <T> >(false, scroller));
     }
 }
        /// <summary>シーケンス内の指定したインデックスにアクセス可能な場合、その位置へ移動する。</summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="scroller"></param>
        /// <param name="index"></param>
        /// <returns></returns>
        public static ResultWithValue <IElementScroller <T> > TryMoveTo <T>(this IElementScroller <T> scroller, int index)
        {
            var cnt = index - scroller.CurrentIndex;

            if (scroller.CanMove(cnt))
            {
                return(new ResultWithValue <IElementScroller <T> >(scroller.MoveTo(cnt)));
            }
            else
            {
                return(new ResultWithValue <IElementScroller <T> >(false, scroller));
            }
        }
        /// <summary>シーケンス内の条件を満たす最後の位置へ移動する。</summary>
        /// <typeparam name="T">要素の型</typeparam>
        /// <param name="scroller">対象インスタンス</param>
        /// <param name="predicate">条件</param>
        public static IElementScroller <T> Last <T>(this IElementScroller <T> scroller, Predicate <T> predicate)
        {
            var s = scroller.GetSequence().Last(x => predicate(x));

            return(scroller.MoveTo(s));
        }
 /// <summary>シーケンス内の最後の位置へ移動する。</summary>
 /// <typeparam name="T">要素の型</typeparam>
 /// <param name="scroller">対象インスタンス</param>
 public static IElementScroller <T> Last <T>(this IElementScroller <T> scroller)
 {
     //return scroller.Move(scroller.GetSequence().Count() - scroller.CurrentIndex - 1);
     return(scroller.MoveTo(scroller.GetSequence().Count() - 1));
 }
 /// <summary>シーケンス内の最初の位置へ移動する。</summary>
 /// <typeparam name="T">要素の型</typeparam>
 /// <param name="scroller">対象インスタンス</param>
 public static IElementScroller <T> First <T>(this IElementScroller <T> scroller)
 {
     //return scroller.Move(1 - scroller.CurrentIndex);
     return(scroller.MoveTo(0));
 }