···46464747 Format.fprintf ppf "%s (%s" filename t.mime_type;
48484949- (match t.size_in_bytes with
5050- | Some size ->
4949+ Option.iter
5050+ (fun size ->
5151 let mb = Int64.to_float size /. (1024. *. 1024.) in
5252- Format.fprintf ppf ", %.1f MB" mb
5353- | None -> ());
5252+ Format.fprintf ppf ", %.1f MB" mb)
5353+ t.size_in_bytes;
54545555- (match t.duration_in_seconds with
5656- | Some duration ->
5555+ Option.iter
5656+ (fun duration ->
5757 let mins = duration / 60 in
5858 let secs = duration mod 60 in
5959- Format.fprintf ppf ", %dm%ds" mins secs
6060- | None -> ());
5959+ Format.fprintf ppf ", %dm%ds" mins secs)
6060+ t.duration_in_seconds;
61616262 Format.fprintf ppf ")"
6363
+2-8
lib/item.ml
···8585let equal a b = a.id = b.id
86868787let compare a b =
8888- match (a.date_published, b.date_published) with
8989- | None, None -> 0
9090- | None, Some _ -> -1
9191- | Some _, None -> 1
9292- | Some da, Some db -> Ptime.compare da db
8888+ Option.compare Ptime.compare a.date_published b.date_published
93899490let pp ppf t =
9591 match (t.date_published, t.title) with
···10399 | None, None -> Format.fprintf ppf "%s" t.id
104100105101let pp_summary ppf t =
106106- match t.title with
107107- | Some title -> Format.fprintf ppf "%s" title
108108- | None -> Format.fprintf ppf "%s" t.id
102102+ Format.fprintf ppf "%s" (Option.value ~default:t.id t.title)
109103110104(* Jsont type *)
111105
+12-18
lib/jsonfeed.ml
···163163 add_error "items must have unique IDs";
164164165165 (* Validate authors *)
166166- (match feed.authors with
167167- | Some authors ->
168168- List.iteri
169169- (fun i author ->
170170- if not (Author.is_valid author) then
171171- add_error
172172- (Printf.sprintf
173173- "feed author %d is invalid (needs at least one field)" i))
174174- authors
175175- | None -> ());
166166+ Option.iter
167167+ (List.iteri (fun i author ->
168168+ if not (Author.is_valid author) then
169169+ add_error
170170+ (Printf.sprintf "feed author %d is invalid (needs at least one field)"
171171+ i)))
172172+ feed.authors;
176173177174 (* Validate items *)
178175 List.iteri
···181178 add_error (Printf.sprintf "item %d has empty ID" i);
182179183180 (* Validate item authors *)
184184- match Item.authors item with
185185- | Some authors ->
186186- List.iteri
187187- (fun j author ->
188188- if not (Author.is_valid author) then
189189- add_error (Printf.sprintf "item %d author %d is invalid" i j))
190190- authors
191191- | None -> ())
181181+ Option.iter
182182+ (List.iteri (fun j author ->
183183+ if not (Author.is_valid author) then
184184+ add_error (Printf.sprintf "item %d author %d is invalid" i j)))
185185+ (Item.authors item))
192186 feed.items;
193187194188 match !errors with [] -> Ok () | errs -> Error (List.rev errs)
+1-1
lib/reference.ml
···2929let pp ppf t =
3030 let open Format in
3131 fprintf ppf "%s" t.url;
3232- match t.doi with Some d -> fprintf ppf " [DOI: %s]" d | None -> ()
3232+ Option.iter (fprintf ppf " [DOI: %s]") t.doi
33333434let jsont =
3535 let kind = "Reference" in
+1-1
lib/rfc3339.ml
···44 ---------------------------------------------------------------------------*)
5566let parse s =
77- match Ptime.of_rfc3339 s with Ok (t, _, _) -> Some t | Error _ -> None
77+ Ptime.of_rfc3339 s |> Result.to_option |> Option.map (fun (t, _, _) -> t)
8899let format t = Ptime.to_rfc3339 ~frac_s:6 ~tz_offset_s:0 t
1010let pp ppf t = Format.pp_print_string ppf (format t)