···4647 Format.fprintf ppf "%s (%s" filename t.mime_type;
4849- (match t.size_in_bytes with
50- | Some size ->
51 let mb = Int64.to_float size /. (1024. *. 1024.) in
52- Format.fprintf ppf ", %.1f MB" mb
53- | None -> ());
5455- (match t.duration_in_seconds with
56- | Some duration ->
57 let mins = duration / 60 in
58 let secs = duration mod 60 in
59- Format.fprintf ppf ", %dm%ds" mins secs
60- | None -> ());
6162 Format.fprintf ppf ")"
63
···4647 Format.fprintf ppf "%s (%s" filename t.mime_type;
4849+ Option.iter
50+ (fun size ->
51 let mb = Int64.to_float size /. (1024. *. 1024.) in
52+ Format.fprintf ppf ", %.1f MB" mb)
53+ t.size_in_bytes;
5455+ Option.iter
56+ (fun duration ->
57 let mins = duration / 60 in
58 let secs = duration mod 60 in
59+ Format.fprintf ppf ", %dm%ds" mins secs)
60+ t.duration_in_seconds;
6162 Format.fprintf ppf ")"
63
+2-8
lib/item.ml
···85let equal a b = a.id = b.id
8687let compare a b =
88- match (a.date_published, b.date_published) with
89- | None, None -> 0
90- | None, Some _ -> -1
91- | Some _, None -> 1
92- | Some da, Some db -> Ptime.compare da db
9394let pp ppf t =
95 match (t.date_published, t.title) with
···103 | None, None -> Format.fprintf ppf "%s" t.id
104105let pp_summary ppf t =
106- match t.title with
107- | Some title -> Format.fprintf ppf "%s" title
108- | None -> Format.fprintf ppf "%s" t.id
109110(* Jsont type *)
111
···85let equal a b = a.id = b.id
8687let compare a b =
88+ Option.compare Ptime.compare a.date_published b.date_published
00008990let pp ppf t =
91 match (t.date_published, t.title) with
···99 | None, None -> Format.fprintf ppf "%s" t.id
100101let pp_summary ppf t =
102+ Format.fprintf ppf "%s" (Option.value ~default:t.id t.title)
00103104(* Jsont type *)
105
+12-18
lib/jsonfeed.ml
···163 add_error "items must have unique IDs";
164165 (* Validate authors *)
166- (match feed.authors with
167- | Some authors ->
168- List.iteri
169- (fun i author ->
170- if not (Author.is_valid author) then
171- add_error
172- (Printf.sprintf
173- "feed author %d is invalid (needs at least one field)" i))
174- authors
175- | None -> ());
176177 (* Validate items *)
178 List.iteri
···181 add_error (Printf.sprintf "item %d has empty ID" i);
182183 (* Validate item authors *)
184- match Item.authors item with
185- | Some authors ->
186- List.iteri
187- (fun j author ->
188- if not (Author.is_valid author) then
189- add_error (Printf.sprintf "item %d author %d is invalid" i j))
190- authors
191- | None -> ())
192 feed.items;
193194 match !errors with [] -> Ok () | errs -> Error (List.rev errs)
···163 add_error "items must have unique IDs";
164165 (* Validate authors *)
166+ Option.iter
167+ (List.iteri (fun i author ->
168+ if not (Author.is_valid author) then
169+ add_error
170+ (Printf.sprintf "feed author %d is invalid (needs at least one field)"
171+ i)))
172+ feed.authors;
000173174 (* Validate items *)
175 List.iteri
···178 add_error (Printf.sprintf "item %d has empty ID" i);
179180 (* Validate item authors *)
181+ Option.iter
182+ (List.iteri (fun j author ->
183+ if not (Author.is_valid author) then
184+ add_error (Printf.sprintf "item %d author %d is invalid" i j)))
185+ (Item.authors item))
000186 feed.items;
187188 match !errors with [] -> Ok () | errs -> Error (List.rev errs)
+1-1
lib/reference.ml
···29let pp ppf t =
30 let open Format in
31 fprintf ppf "%s" t.url;
32- match t.doi with Some d -> fprintf ppf " [DOI: %s]" d | None -> ()
3334let jsont =
35 let kind = "Reference" in
···29let pp ppf t =
30 let open Format in
31 fprintf ppf "%s" t.url;
32+ Option.iter (fprintf ppf " [DOI: %s]") t.doi
3334let jsont =
35 let kind = "Reference" in
+1-1
lib/rfc3339.ml
···4 ---------------------------------------------------------------------------*)
56let parse s =
7- match Ptime.of_rfc3339 s with Ok (t, _, _) -> Some t | Error _ -> None
89let format t = Ptime.to_rfc3339 ~frac_s:6 ~tz_offset_s:0 t
10let pp ppf t = Format.pp_print_string ppf (format t)
···4 ---------------------------------------------------------------------------*)
56let parse s =
7+ Ptime.of_rfc3339 s |> Result.to_option |> Option.map (fun (t, _, _) -> t)
89let format t = Ptime.to_rfc3339 ~frac_s:6 ~tz_offset_s:0 t
10let pp ppf t = Format.pp_print_string ppf (format t)