コード例 #1
0
        public static async Task <TResult> ToDictionaryAsync <TKey, TValue, TKeyDictionary, TValueDictionary, TResult>(this IEnumerableAsync <KeyValuePair <TKey, TValue> > kvpItems,
                                                                                                                       Func <KeyValuePair <TKey, TValue>, TKeyDictionary> selectKey,
                                                                                                                       Func <KeyValuePair <TKey, TValue>, TValueDictionary> selectValue,
                                                                                                                       Func <Dictionary <TKeyDictionary, TValueDictionary>, KeyValuePair <TKey, TValue>[], TResult> dictionaryAndDuplicates)
        {
            var hashSet       = new HashSet <TKey>();
            var kvpItemsArray = await kvpItems.ToArrayAsync();

            var duplicates = new KeyValuePair <TKey, TValue>[] { };
            var dictionary = kvpItemsArray
                             .Select(
                kvp =>
            {
                if (hashSet.Contains(kvp.Key))
                {
                    duplicates = duplicates.Append(kvp).ToArray();
                    return(default(KeyValuePair <TKeyDictionary, TValueDictionary>?));
                }
                hashSet.Add(kvp.Key);
                return(selectValue(kvp).PairWithKey(selectKey(kvp)));
            })
                             .SelectWhereHasValue()
                             .ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

            return(dictionaryAndDuplicates(dictionary, duplicates));
        }
コード例 #2
0
        public static async Task <IRefs <T> > AsRefsAsync <T>(this IEnumerableAsync <Guid> ids)
            where T : IReferenceable
        {
            var idsArray = await ids.ToArrayAsync();

            return(new Refs <T>(idsArray));
        }