예제 #1
0
        /// <summary>
        /// Returns the key-value pair at the specified index in the ordered map, by key order.
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentOutOfRangeException">If the index is out of range</exception>
        public KeyValuePair <TKey, TValue> ByOrder(int index)
        {
            index.CheckIsBetween("index", -Root.Count, Root.Count - 1);
            index = index < 0 ? index + Root.Count : index;
            var opt = Root.ByOrder(index);

            return(Kvp.Of(opt.Key, opt.Value));
        }
예제 #2
0
 /// <summary>
 ///     Applies the specified function on every item in the collection, from last to first, and stops when the function returns false.
 /// </summary>
 /// <param name="function"> The function. </param>
 /// <returns> </returns>
 /// <exception cref="ArgumentNullException">Thrown if the argument null.</exception>
 public override bool ForEachWhile(Func <KeyValuePair <TKey, TValue>, bool> function)
 {
     function.CheckNotNull("function");
     return(_root.ForEachWhile((eqKey, v) => function(Kvp.Of(eqKey, v))));
 }
예제 #3
0
파일: ImmMap.cs 프로젝트: stjordanis/Imms
 /// <summary>
 /// Converts the specified sequence into a ImmMap, using the key and value selectors to determine the keys and values.
 /// </summary>
 /// <typeparam name="T">The type of value contained in the sequence.</typeparam>
 /// <typeparam name="TKey">The type of key selected.</typeparam>
 /// <typeparam name="TValue"></typeparam>
 /// <param name="sequence"></param>
 /// <param name="keySelector"></param>
 /// <param name="valueSelector"></param>
 /// <param name="equality"></param>
 /// <returns></returns>
 public static ImmMap <TKey, TValue> ToImmMap <T, TKey, TValue>(this IEnumerable <T> sequence, Func <T, TKey> keySelector,
                                                                Func <T, TValue> valueSelector, IEqualityComparer <TKey> equality)
 {
     return(sequence.Select(x => Kvp.Of(keySelector(x), valueSelector(x))).ToImmMap(equality));
 }