-
Notifications
You must be signed in to change notification settings - Fork 127
Open
Description
Currently, the Arbitrary instance for NonEmpty generates a nonempty list and then converts it to a NonEmpty:
liftArbitrary arb = NonEmpty.fromList <$> listOf1 arbThis 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 . nonEmptyListOfMetadata
Metadata
Assignees
Labels
No labels