ByKey <TKey, TValue>(TKey key) { return (Lens.Create <IImmutableDictionary <TKey, TValue>, TValue>( dictionary => dictionary[key], value => dictionary => dictionary.SetItem(key, value))); }
Location <TValue>(int x, int y) { return(Lens .Create <IImmutableGrid <TValue>, TValue>( grid => grid[x, y], value => grid => grid.Set(x, y, value))); }
Lookup <TKey, TValue>(TKey key, Func <TKey, TValue> defaultFactory) { return (Lens.Create <IImmutableDictionary <TKey, TValue>, TValue>( dictionary => dictionary.Lookup(key).OrElse(defaultFactory(key)), // ReSharper disable once ImplicitlyCapturedClosure value => dictionary => dictionary.SetItem(key, value))); }
Lookup <TKey, TValue>(TKey key) { return (Lens.Create <IImmutableDictionary <TKey, TValue>, IMaybe <TValue> >( dictionary => dictionary.Lookup(key), value => dictionary => { return value .Select(x => dictionary.SetItem(key, x)) .OrElse(() => dictionary.Remove(key)); })); }