Created
August 28, 2015 16:40
-
-
Save beckyconning/228a44cd87d50bb82df7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
newtype AtLeastTwoAndUnique a = AtLeastTwoAndUnique (Array a) | |
toArray :: forall a. AtLeastTwoAndUnique a -> Array a | |
toArray (AtLeastTwoAndUnique xs) = xs | |
first :: forall a. AtLeastTwoAndUnique a -> a | |
first = Unsafe.head | |
instance arbAtLeastTwoAndUnique :: (Arbitrary a) => Arbitrary (AtLeastTwoAndUnique a) where | |
arbitrary = AtLeastTwoAndUnique <$> arbitrary `suchThat` (\xs -> unique xs && atLeastTwo xs) | |
where | |
unique xs = nub xs == xs | |
atLeastTwo = (>= 2) <<< length |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
newtype AtLeastTwoAndUnique a = AtLeastTwoAndUnique (Tuple (Tuple a a) (Array a)) | |
toArray :: forall a. AtLeastTwoAndUnique a -> Array a | |
toArray (AtLeastTwoAndUnique (Tuple (Tuple x1 x2) xs)) = x1 : x2 : xs | |
first :: forall a. AtLeastTwoAndUnique a -> a | |
first (AtLeastTwoAndUnique (Tuple tuple _)) = fst tuple | |
instance arbAtLeastTwoAndUnique :: (Arbitrary a, Ord a, Show a) => Arbitrary (AtLeastTwoAndUnique a) where | |
arbitrary = AtLeastTwoAndUnique <$> arbitrary `suchThat` unique | |
where | |
unique (Tuple (Tuple x1 x2) xs) = nub (x1 : x2 :xs) == (x1 : x2 : xs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment