nick8325 / nick8325/quickcheck

Clean up NonEmpty

Open
#457 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Haskell
Stars
790
Forks
130
Avg merge
16h 41m
Merged PRs (30d)
2

Description

Currently, the Arbitrary instance for NonEmpty generates a nonempty list and then converts it to a NonEmpty:

  liftArbitrary arb = NonEmpty.fromList <$> listOf1 arb

This isn't very nice, since it uses a partial function unnecessarily. We could do this instead:

  liftArbitrary = nonEmptyListOf
 
nonEmptyListOf :: Gen a -> Gen (NonEmpty a)
nonEmptyListOf gen = sized $ \n -> do
  k <- chooseInt (0, 0 `max` (n - 1))
  liftA2 (:|) gen (vectorOf k gen)

-- To avoid duplication, we could redefine listOf1:
listOf1 :: Gen a -> Gen [a]
listOf1 = fmap toList . nonEmptyListOf

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the Arbitrary instance for NonEmpty and the existing listOf1 implementation mentioned in the issue. Check the relevant QuickCheck tests, then confirm that generation no longer relies on a partial conversion and that the existing list-generation behavior remains covered.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell
Domain
testing-qa
Issue type
Refactor
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.