Skip to content

Commit 143ab91

Browse files
author
Nathan Rebours
committed
Extract Stdlib0.List.without_first
This will prove useful for other similar migrations Signed-off-by: Nathan Rebours <nathan.rebours@ocamlpro.com>
1 parent 7b31839 commit 143ab91

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

astlib/encoding_505.ml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
open Stdlib0
2+
13
module Ext_name = struct
24
let pexp_struct_item = "ppxlib.migration.pexp_struct_item_505"
35
let ptyp_functor = "ppxlib.migration.ptyp_functor_505"
@@ -92,14 +94,9 @@ module To_504 = struct
9294
| _ -> None
9395

9496
let must_preserve_ppat_constraint l =
95-
let rec aux seen = function
96-
| [] -> None
97-
| { attr_name = { txt; _ }; _ } :: tl
98-
when String.equal txt Ext_name.preserve_ppat_constraint ->
99-
Some (List.rev_append seen tl)
100-
| hd :: tl -> aux (hd :: seen) tl
101-
in
102-
aux [] l
97+
List.without_first l
98+
~pred:(fun attr ->
99+
String.equal attr.attr_name.txt Ext_name.preserve_ppat_constraint)
103100

104101
let preserve_ppat_constraint pattern core_type =
105102
let loc = pattern.ppat_loc in

astlib/stdlib0.ml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,15 @@ module String = struct
1818
String.length t >= String.length prefix
1919
&& is_prefix_from t ~prefix ~pos:0 ~len:(String.length prefix)
2020
end
21+
22+
module List = struct
23+
include List
24+
25+
let without_first list ~pred =
26+
let rec aux seen = function
27+
| [] -> None
28+
| hd::tl when pred hd -> Some (List.rev_append seen tl)
29+
| hd::tl -> aux (hd::seen) tl
30+
in
31+
aux [] list
32+
end

0 commit comments

Comments
 (0)