Commit
+12 -9 +/-3 browse
1 | diff --git a/lib/note.ml b/lib/note.ml |
2 | index 6be04a2..fa5491a 100644 |
3 | --- a/lib/note.ml |
4 | +++ b/lib/note.ml |
5 | @@ -111,11 +111,14 @@ let of_string ?(path = None) content = |
6 | module Tree = struct |
7 | type tree = Tree of (t * tree list) |
8 | |
9 | - let rec flatten ?(accm = []) tree = |
10 | - let (Tree (note, others)) = tree in |
11 | - List.fold ~init:(note :: accm) |
12 | - ~f:(fun accm note -> flatten ~accm note) |
13 | - others |
14 | + let flatten tree = |
15 | + let rec flatten ~accm tree = |
16 | + let (Tree (note, others)) = tree in |
17 | + List.fold ~init:(note :: accm) |
18 | + ~f:(fun accm note -> flatten ~accm note) |
19 | + others |
20 | + in |
21 | + tree |> flatten ~accm:[] |
22 | |
23 | let fst tree = |
24 | let (Tree (note, _)) = tree in |
25 | diff --git a/lib/note.mli b/lib/note.mli |
26 | index d811946..33b631d 100644 |
27 | --- a/lib/note.mli |
28 | +++ b/lib/note.mli |
29 | @@ -28,7 +28,7 @@ module Tree : sig |
30 | val fst : tree -> t |
31 | (* return the top level note of a given tree *) |
32 | |
33 | - val flatten : ?accm:t list -> tree -> t list |
34 | + val flatten : tree -> t list |
35 | (* flatten a tree into a list of notes *) |
36 | end |
37 | |
38 | diff --git a/test/note_test.ml b/test/note_test.ml |
39 | index db2edb4..6d25e88 100644 |
40 | --- a/test/note_test.ml |
41 | +++ b/test/note_test.ml |
42 | @@ -31,17 +31,17 @@ let adapter () = |
43 | let tree = options |> Note.load ~path:"/" in |
44 | Alcotest.(check int) |
45 | "initialized" 1 |
46 | - (tree |> Note.Tree.flatten ~accm:[] |> List.length); |
47 | + (tree |> Note.Tree.flatten |> List.length); |
48 | options |> Note.create ~content:(Some "bar") ~path:"/fuu"; |
49 | let tree = options |> Note.load ~path:"/" in |
50 | Alcotest.(check int) |
51 | "note added" 2 |
52 | - (tree |> Note.Tree.flatten ~accm:[] |> List.length); |
53 | + (tree |> Note.Tree.flatten |> List.length); |
54 | options |> Note.remove ~path:"/fuu"; |
55 | let tree = options |> Note.load ~path:"/" in |
56 | Alcotest.(check int) |
57 | "note removed" 1 |
58 | - (tree |> Note.Tree.flatten ~accm:[] |> List.length) |
59 | + (tree |> Note.Tree.flatten |> List.length) |
60 | |
61 | let suggest_path () = |
62 | let options : Note.options = |