public static IDistinctValuedDictionary <TValue, TKey> Invert <TKey, TValue>(this IDistinctValuedDictionary <TKey, TValue> dictionary) { var invertedDictionary = new Dictionary <TValue, TKey>().AsDistinctValued(); dictionary.ForEach(pair => invertedDictionary.Add(pair.Value, pair.Key)); return(invertedDictionary); }
public async Task <IDictionary <TKey, string> > ReadContentsByKey <TKey>(IDistinctValuedDictionary <TKey, string> filePathsByKey) { var output = new Dictionary <TKey, string>(); foreach (var pair in filePathsByKey) { var content = await FileHelper.Read(pair.Value); output.Add(pair.Key, content); } return(output); }
// Sync. public static IDictionary <TKey, TOut> ProcessByKey <TKey, TIn, TOut>( Func <TIn, TOut> processor, IDistinctValuedDictionary <TKey, TIn> inputsByKey) { var output = new Dictionary <TKey, TOut>(); foreach (var pair in inputsByKey) { var result = processor(pair.Value); output.Add(pair.Key, result); } return(output); }
public Task <IDictionary <TKey, bool> > DeleteFilesByKey <TKey>(IDistinctValuedDictionary <TKey, string> filePathsByKey) { var output = new Dictionary <TKey, bool>(); foreach (var pair in filePathsByKey) { var exists = FileHelper.Exists(pair.Value); FileHelper.DeleteOnlyIfExists(pair.Value); output.Add(pair.Key, exists); } return(Task.FromResult(output as IDictionary <TKey, bool>)); }
public static IDistinctValuedDictionary <TKey, string> GetFilePathsByKey <TKey>(this IStringlyTypedPathOperator stringlyTypedPathOperator, string directoryPath, IDistinctValuedDictionary <TKey, string> fileNamesByKey) { return(fileNamesByKey.ToDictionary( pair => pair.Key, pair => stringlyTypedPathOperator.GetFilePath(directoryPath, pair.Value)) .AsDistinctValued()); }
public static async Task <IDictionary <TKey, bool> > ExistsFilesByKey <TKey>(this IFileSystemOperator @operator, IDistinctValuedDictionary <TKey, string> filePathsByKey) { var keysByFilePath = filePathsByKey.Invert(); var existsByFilePath = await @operator.ExistsFiles(keysByFilePath.Keys.AsDistinct()); var output = keysByFilePath.Join(existsByFilePath, keys => keys.Key, exists => exists.Key, (keys, exists) => (Key: keys.Value, Exists: exists.Value)) .ToDictionary( x => x.Key, x => x.Exists); return(output); }