module Hashtbloper:Hash table convenience operatorssig..end
These are operators to help make your work with hash tables easier. For other
utitilies, see also the Hashtblutil.
Unlike the functions in Hashtblutil, all of these operators are
non-destructive. That is, they do not modify the hash tables on which
they operate, but rather return a new hash table that represents the result.
This leads to the most natural behavior for an operator.
val (/>) : ('a, 'b) Hashtbl.t -> 'a -> 'b
hash /> 5
is the same as:
Hashtbl.find hash 5
This can be combined to form more powerful constructs. Consider this example:
let sections = Hashtbl.create 5;;
let options = Hashtbl.create 5;;
Hashtbl.replace options "option1" "value1";;
Hashtbl.replace sections "section1" options;;
sections /> "section1" /> "option1";;
returns "value1" val (/+) : ('a, 'b) Hashtbl.t -> ('a, 'b) Hashtbl.t -> ('a, 'b) Hashtbl.t
hash1 /+ hash2
Returns a new hash (hash1 and hash2 are unmodified). It will contain
all key/value pairs in either hash. If any pairs are duplicated, the
values in hash2 take precedence.
val (//) : ('a, 'b) Hashtbl.t -> 'a * 'b -> ('a, 'b) Hashtbl.tFor example:
let newhash = hash // ("key", "value");;
This will return a new hash that has the elements of hash plus one more.