Skip to content

Commit

Permalink
Add example for Gen.subsequence (#450)
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-martin authored and jacobstanley committed May 22, 2022
1 parent 4c16408 commit 2e32700
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions hedgehog/src/Hedgehog/Internal/Gen.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1661,6 +1661,20 @@ subterm3 gx gy gz f =

-- | Generates a random subsequence of a list.
--
-- For example:
--
-- @
-- Gen.print (Gen.subsequence [1..5])
-- @
--
-- > === Outcome ===
-- > [1,2,4]
-- > === Shrinks ===
-- > []
-- > [2,4]
-- > [1,4]
-- > [1,2]
--
subsequence :: MonadGen m => [a] -> m [a]
subsequence xs =
shrink Shrink.list $ filterM (const bool_) xs
Expand Down

0 comments on commit 2e32700

Please sign in to comment.