nick8325 / nick8325/quickcheck
Clean up NonEmpty
Open
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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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