Example #1
0
 /// <summary>
 /// Retrieve a value from the map by key and pattern match the
 /// result.
 /// </summary>
 /// <param name="key">Key to find</param>
 /// <returns>Found value</returns>
 public R Find <R>(K key, Func <V, R> Some, Func <R> None) =>
 key == null
         ? None()
         : match(MapModule.TryFind(Root, key, Comparer <K> .Default), Some, None);
Example #2
0
 /// <summary>
 /// Retrieve a value from the map by key
 /// </summary>
 /// <param name="key">Key to find</param>
 /// <returns>Found value</returns>
 public Option <V> Find(K key) =>
 key == null
         ? None
         : MapModule.TryFind(Root, key, Comparer <K> .Default);
Example #3
0
 public bool Contains(KeyValuePair <K, V> pair) =>
 match(MapModule.TryFind(Root, pair.Key, Comparer <K> .Default),
       Some: v => ReferenceEquals(v, pair.Value),
       None: () => false);
Example #4
0
 public Map <K, V> AddOrUpdate(K key, Func <V, V> Some, Func <V> None) =>
 isnull(key)
         ? this
         : match(MapModule.TryFind(Root, key, Comparer <K> .Default),
                 Some: x => SetItem(key, Some(x)),
                 None: () => Add(key, None()));
Example #5
0
 public Map <K, V> TrySetItem(K key, Func <V, V> Some, Func <Map <K, V>, Map <K, V> > None) =>
 isnull(key)
         ? this
         : match(MapModule.TryFind(Root, key, Comparer <K> .Default),
                 Some: x => SetItem(key, Some(x)),
                 None: () => None(this));
Example #6
0
 public Map <K, V> SetItem(K key, Func <V, V> Some) =>
 isnull(key)
         ? this
         : match(MapModule.TryFind(Root, key, Comparer <K> .Default),
                 Some: x => SetItem(key, Some(x)),
                 None: () => raise <Map <K, V> >(new ArgumentException("Key not found in Map")));