Last active
April 17, 2019 14:24
-
-
Save dadhi/bafd75fd4e7f9d004faa24e53156f3d8 to your computer and use it in GitHub Desktop.
Wrapping immutable value in a mutable box
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using ImTools; | |
public class Program | |
{ | |
public static void Main() | |
{ | |
var map = ImHashMap<string, string>.Empty; | |
var map1 = map.AddOrUpdate("a", "42"); | |
Console.WriteLine(map1.GetValueOrDefault("a")); | |
} | |
} | |
public static class Ext | |
{ | |
public static void Add<K, V>(this Ref<ImHashMap<K, V>> map, K key, V value) | |
{ | |
map.Swap(m => m.AddOrUpdate(key, value)); | |
} | |
} | |
public static class FamiliarApi | |
{ | |
public static void Example() | |
{ | |
var map = Ref.Of(ImHashMap<string, string>.Empty); | |
map.Add("b", "3.14"); | |
Console.WriteLine(map.Value.GetValueOrDefault("b")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment