FSharpPlus


NonEmptyMap<'Key, 'Value>

A type-safe map that contains at least one element.

Examples

#r @"nuget: FSharpPlus"
open FSharpPlus
open FSharpPlus.Data

Constructing NonEmptyMap

// you can construct a NonEmptyMap by using NonEmptyMap.Create
let map1 = NonEmptyMap.Create(("a", 1), ("b", 2))

let map2 = NonEmptyMap.singleton "c" 3

// in order to get back to a regular map you can then use NonEmptyMap.toMap:
let map1' = NonEmptyMap.toMap map1

Operations on NonEmptyMap

let map3 = map1 |> NonEmptyMap.add "d" 4

let map4 = NonEmptyMap.union map2 map3

map4 |> NonEmptyMap.tryFind "c" |> printfn "%A"
namespace FSharpPlus
namespace FSharpPlus.Data
val map1: NonEmptyMap<string,int>
Multiple items
module NonEmptyMap from FSharpPlus.Data
<summary> Basic operations on NonEmptyMap </summary>

--------------------
type NonEmptyMap<'Key,'Value (requires comparison)> = private { Value: Map<'Key,'Value> } interface IReadOnlyDictionary<'Key,'Value> interface NonEmptySeq<KeyValuePair<'Key,'Value>> interface IReadOnlyCollection<KeyValuePair<'Key,'Value>> interface IEnumerable<KeyValuePair<'Key,'Value>> interface IEnumerable member Add: key: 'Key * value: 'Value -> NonEmptyMap<'Key,'Value> member ContainsKey: key: 'Key -> bool member TryFind: key: 'Key -> 'Value option member TryGetValue: key: 'Key * [<Out>] value: byref<'Value> -> bool static member Create: ('Key * 'Value) * [<ParamArray>] rest: ('Key * 'Value) array -> NonEmptyMap<'Key,'Value> ...
<summary> A type-safe map that contains at least one element. </summary>
static member NonEmptyMap.Create: ('Key * 'Value) * [<System.ParamArray>] rest: ('Key * 'Value) array -> NonEmptyMap<'Key,'Value>
val map2: NonEmptyMap<string,int>
val singleton: key: 'a -> value: 'b -> NonEmptyMap<'a,'b> (requires comparison)
<summary>Builds a non empty map with a single element.</summary>
val map1': Map<string,int>
val toMap: NonEmptyMap<'a,'b> -> Map<'a,'b> (requires comparison)
<summary>Builds a map from the given non empty map.</summary>
val map3: NonEmptyMap<string,int>
val add: key: 'a -> value: 'b -> table: NonEmptyMap<'a,'b> -> NonEmptyMap<'a,'b> (requires comparison)
<summary>Returns a new map with the binding added to the given map. If a binding with the given key already exists in the input map, the existing binding is replaced by the new binding in the result map.</summary>
<param name="key">The input key.</param>
<param name="value">The input value.</param>
<param name="table">The input map.</param>
<returns>The resulting map.</returns>
val map4: NonEmptyMap<string,int>
val union: source: NonEmptyMap<'Key,'T> -> altSource: NonEmptyMap<'Key,'T> -> NonEmptyMap<'Key,'T> (requires comparison)
<summary> Returns the union of two maps, preferring values from the first in case of duplicate keys. </summary>
val tryFind: key: 'a -> table: NonEmptyMap<'a,'b> -> 'b option (requires comparison)
<summary>Lookup an element in the map, returning a <c>Some</c> value if the element is in the domain of the map and <c>None</c> if not.</summary>
<param name="key">The input key.</param>
<param name="table">The input map.</param>
<returns>The found <c>Some</c> value or <c>None</c>.</returns>
val printfn: format: Printf.TextWriterFormat<'T> -> 'T