Skip to content

Commit 937e057

Browse files
authored
Merge pull request #380 from jmid/map-renaming
The Great Renaming, Chapter 10: `map` renaming
2 parents 2cb9592 + e8f06c3 commit 937e057

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
- Renamed monadic and applicative generator combinators:
8282
- Add missing `QCheck.Gen.bind` for consistency
8383
- Add missing `QCheck.Gen.ap` for consistency
84+
- Add missing `QCheck2.Gen.map_keep_input` for consistency
8485

8586

8687
## 0.27 (2025-10-31)

src/core/QCheck2.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,8 @@ module Gen = struct
352352

353353
let map5 = liftA5
354354

355+
let map_keep_input f x = fun st -> Tree.map (fun a -> a, f a) (x st)
356+
355357
let return = pure
356358

357359
let bind (gen : 'a t) (f : 'a -> ('b t)) : 'b t = fun st ->

src/core/QCheck2.mli

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,6 +1181,15 @@ module Gen : sig
11811181
@since 0.25
11821182
*)
11831183

1184+
val map_keep_input : ('a -> 'b) -> 'a t -> ('a * 'b) t
1185+
(** [map_keep_input f g] transforms a generator [g] by applying [f] to each generated element.
1186+
Returns both the generated element from [g] and the output from [f].
1187+
1188+
Shrinks towards the shrinks of [g] with [f] applied to them.
1189+
1190+
@since NEXT_RELEASE
1191+
*)
1192+
11841193
val ap : ('a -> 'b) t -> 'a t -> 'b t
11851194
(** [ap fgen gen] composes a function generator and an argument generator
11861195
into a result generator.

0 commit comments

Comments
 (0)