//========================================================================= // (c) Microsoft Corporation 2005-2009. //========================================================================= namespace Microsoft.FSharp.Collections open System open System.Collections.Generic open Microsoft.FSharp.Core open Microsoft.FSharp.Collections /// Immutable maps. Keys are ordered by F# generic comparison. /// /// /// Maps based on generic comparison are efficient for small keys. They are not a suitable choice if keys are recursive data structures /// or if keys require bespoke comparison semantics. /// [] type Map<'Key,'Value> = /// Return a new map with the binding added to the given map. member Add: key:'Key * value:'Value -> Map<'Key,'Value> /// Return true if there are no bindings in the map. member IsEmpty: bool /// Build a map that contains the bindings of the given IEnumerable new : elements:seq<'Key * 'Value> -> Map<'Key,'Value> /// The empty map static member Empty: Map<'Key,'Value> /// Test if an element is in the domain of the map member ContainsKey: key:'Key -> bool /// The number of bindings in the map member Count: int /// Lookup an element in the map. Raise KeyNotFoundException if no binding /// exists in the map. member Item : key:'Key -> 'Value with get /// Remove an element from the domain of the map. No exception is raised if the element is not present. member Remove: key:'Key -> Map<'Key,'Value> /// Lookup an element in the map, returning a Some value if the element is in the domain /// of the map and None if not. member TryFind: key:'Key -> 'Value option interface IDictionary<'Key, 'Value> interface ICollection> interface IEnumerable> interface System.IComparable interface System.Collections.IEnumerable override Equals : obj -> bool /// Functional programming operators related to the Map<_,_> type. [] [] module Map = /// Return a new map with the binding added to the given map. val add: key:'Key -> value:'T -> table:Map<'Key,'T> -> Map<'Key,'T> /// Return a new map made from the given bindings val of_list: elements:('Key * 'T) list -> Map<'Key,'T> /// Return a new map made from the given bindings val of_array: elements:('Key * 'T) array -> Map<'Key,'T> /// Return a new map made from the given bindings val of_seq: elements:seq<'Key * 'T> -> Map<'Key,'T> /// View the collection as an enumerable sequence. This collection /// type is also directly compatible with 'seq<KeyValuePair<_,_> >'. /// /// Note this function returns a sequence of tuples, whereas the collection /// itself is compatible with the logically equivalent sequence of KeyValuePairs. /// Using sequences of tuples tends to be more convenient in F#, however the /// collection itself must enumerate KeyValuePairs to conform to the .NET /// design guidelines and the IDictionary interface. val to_seq: table:Map<'Key,'T> -> seq<'Key * 'T> /// Returns a list of all key-value pairs in the mappinng val to_list: table:Map<'Key,'T> -> list<'Key * 'T> /// Returns an array of all key-value pairs in the mappinng val to_array: table:Map<'Key,'T> -> ('Key * 'T) array /// Is the map empty? val isEmpty: table:Map<'Key,'T> -> bool [] val is_empty: table:Map<'Key,'T> -> bool /// The empty map [] val empty<'Key,'T> : Map<'Key,'T> /// Lookup an element in the map, raising KeyNotFoundException if no binding /// exists in the map. val find: key:'Key -> table:Map<'Key,'T> -> 'T /// Search the map looking for the first element where the given function returns a Some value val tryPick: chooser:('Key -> 'T -> 'U option) -> table:Map<'Key,'T> -> 'U option /// Search the map looking for the first element where the given function returns a Some value val pick: chooser:('Key -> 'T -> 'U option) -> table:Map<'Key,'T> -> 'U /// Fold over the bindings in the map val foldBack: folder:('Key -> 'T -> 'State -> 'State) -> table:Map<'Key,'T> -> state:'State -> 'State /// Fold over the bindings in the map val fold: folder:('State -> 'Key -> 'T -> 'State) -> state:'State -> table:Map<'Key,'T> -> 'State /// Apply the given function to each binding in the dictionary val iter: action:('Key -> 'T -> unit) -> table:Map<'Key,'T> -> unit /// Return true if the given predicate returns true for one of the /// bindings in the map. val exists: predicate:('Key -> 'T -> bool) -> table:Map<'Key, 'T> -> bool /// Build a new map containing only the bindings for which the given predicate returns 'true' val filter: predicate:('Key -> 'T -> bool) -> table:Map<'Key, 'T> -> Map<'Key, 'T> /// Return true if the given predicate returns true for all of the /// bindings in the map. val forall: predicate:('Key -> 'T -> bool) -> table:Map<'Key, 'T> -> bool /// Build a new collection whose elements are the results of applying the given function /// to each of the elements of the collection. The index passed to the /// function indicates the index of element being transformed. val map: mapping:('Key -> 'T -> 'U) -> table:Map<'Key,'T> -> Map<'Key,'U> /// Test is an element is in the domain of the map val contains: key:'Key -> table:Map<'Key,'T> -> bool /// Build two new maps, one containing the bindings for which the given predicate returns 'true', /// and the other the remaining bindings. val partition: predicate:('Key -> 'T -> bool) -> table:Map<'Key, 'T> -> Map<'Key, 'T> * Map<'Key, 'T> /// Remove an element from the domain of the map. No exception is raised if the element is not present. val remove: key:'Key -> table:Map<'Key,'T> -> Map<'Key,'T> /// Lookup an element in the map, returning a Some value if the element is in the domain /// of the map and None if not. val tryFind: key:'Key -> table:Map<'Key,'T> -> 'T option /// Evaluates the function on each mapping in the collection. Returns the key for the first mapping /// where the function returns 'true'. Raise KeyNotFoundException if no such element exists. val findIndex: predicate:('Key -> 'T -> bool) -> table:Map<'Key,'T> -> 'Key /// Return the key of the first mapping in the collection that satisfies the given predicate. /// Return 'None' if no such element exists. val tryFindIndex: predicate:('Key -> 'T -> bool) -> table:Map<'Key,'T> -> 'Key option #if DONT_INCLUDE_DEPRECATED #else /// Search the map looking for the first element where the given function returns a Some value [] val first: chooser:('Key -> 'T -> 'U option) -> table:Map<'Key,'T> -> 'U option [] val fold_right: folder:('Key -> 'T -> 'State -> 'State) -> table:Map<'Key,'T> -> state:'State -> 'State [] val fold_left: folder:('State -> 'Key -> 'T -> 'State) -> state:'State -> table:Map<'Key,'T> -> 'State [] val for_all: predicate:('Key -> 'T -> bool) -> table:Map<'Key, 'T> -> bool [] val mapi: mapping:('Key -> 'T -> 'U) -> table:Map<'Key,'T> -> Map<'Key,'U> [] val mem: key:'Key -> table:Map<'Key,'T> -> bool [] val tryfind: key:'Key -> table:Map<'Key,'T> -> 'T option [] val find_index: predicate:('Key -> 'T -> bool) -> table:Map<'Key,'T> -> 'Key [] val tryfind_index: predicate:('Key -> 'T -> bool) -> table:Map<'Key,'T> -> 'Key option #endif