Commits

bergsoe  committed dbe453a

[map_adjacent] utility.

  • Participants
  • Parent commits 5fd9032

Comments (0)

Files changed (2)

File src/PaplPath.ml

                 loop (x1 :: rest) (f x0 x1 acc)
             | _ -> acc
         in loop xs acc
+
+let map_adjacent f xs =
+  let rec loop prev xs =
+    match xs with
+        next :: xs ->
+          let y = f prev next in
+            y :: loop next xs
+      | [] -> []
+  in
+    match xs with
+        [] -> invalid_arg "PaplPath.map_adjacent: empty path."
+      | [_] -> invalid_arg "Papl_path.fold_adjacent: one-element path."
+      | next :: xs ->
+          loop next xs

File src/PaplPath.mli

 (** {2 Operations} *)
 
 val fold_adjacent : ('a -> 'a -> 'acc -> 'acc) -> 'a t -> 'acc -> 'acc
-(** [fold_adjacent f \[q(1), q(2), ..., q(N)\] acc] is equivalent to
+(** [fold_adjacent f \[q(1); q(2); ...; q(N)\] acc] is equivalent to
     [f q(N-1) q(N) ... (f q(2) q(3) (f q(1) q(2) acc))].
 *)
+
+val map_adjacent : ('a -> 'a -> 'b) -> 'a t -> 'b t
+(** [map_adjacent f \[q(1); q(2); ...; q(N)\]] is equivalent to
+    [\[f q(1) q(2); f q(2) q(3); ...; f q(1) q(2)\]].
+*)