Skip to content

Commit e3b6e80

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 e90b23c commit e3b6e80

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
@@ -30,3 +30,15 @@ module Option = struct
3030
aux [] l
3131
end
3232
end
33+
34+
module List = struct
35+
include List
36+
37+
let without_first list ~pred =
38+
let rec aux seen = function
39+
| [] -> None
40+
| hd::tl when pred hd -> Some (List.rev_append seen tl)
41+
| hd::tl -> aux (hd::seen) tl
42+
in
43+
aux [] list
44+
end

0 commit comments

Comments
 (0)