Add more derive-shows to some monitor-related types
[hiphop-php.git] / hphp / hack / src / utils / collections / sSet.ml
blobb422c40db5b64ca96ee23669e40f306669f6e28a
1 (*
2 * Copyright (c) 2015, Facebook, Inc.
3 * All rights reserved.
5 * This source code is licensed under the MIT license found in the
6 * LICENSE file in the "hack" directory of this source tree.
8 *)
10 include Set.Make (StringKey)
12 let pp_limit ?(max_elts = None) fmt sset =
13 Format.fprintf fmt "@[<2>{";
14 let elements = elements sset in
15 (match elements with
16 | [] -> ()
17 | _ -> Format.fprintf fmt " ");
18 let (_ : int) =
19 List.fold_left
20 (fun i s ->
21 (match max_elts with
22 | Some max_elts when i >= max_elts -> ()
23 | _ ->
24 if i > 0 then Format.fprintf fmt ";@ ";
25 Format.fprintf fmt "%S" s);
26 i + 1)
28 elements
30 (match elements with
31 | [] -> ()
32 | _ -> Format.fprintf fmt " ");
33 Format.fprintf fmt "@,}@]"
35 let pp = pp_limit ~max_elts:None
37 let show sset = Format.asprintf "%a" pp sset
39 let to_string = show
41 let pp_large ?(max_elts = 5) fmt sset =
42 let l = cardinal sset in
43 if l <= max_elts then
44 pp fmt sset
45 else
46 Format.fprintf
47 fmt
48 "<only showing %d of %d elems: %a>"
49 max_elts
51 (pp_limit ~max_elts:(Some max_elts))
52 sset
54 let show_large ?(max_elts = 5) sset =
55 Format.asprintf "%a" (pp_large ~max_elts) sset