packages feed

nonempty-wrapper-quickcheck (empty) → 0.1.0.0

raw patch · 3 files changed

+106/−0 lines, 3 filesdep +QuickCheckdep +basedep +nonempty-wrapper

Dependencies added: QuickCheck, base, nonempty-wrapper

Files

+ LICENSE view
@@ -0,0 +1,15 @@+ISC License++Copyright (c) 2022 Gautier DI FOLCO++Permission to use, copy, modify, and/or distribute this software for any+purpose with or without fee is hereby granted, provided that the above+copyright notice and this permission notice appear in all copies.++THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH+REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY+AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,+INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM+LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR+OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR+PERFORMANCE OF THIS SOFTWARE.
+ nonempty-wrapper-quickcheck.cabal view
@@ -0,0 +1,49 @@+cabal-version:       3.0+name:                nonempty-wrapper-quickcheck+version:             0.1.0.0+author:              Gautier DI FOLCO+maintainer:          gautier.difolco@gmail.com+category:            Data+build-type:          Simple+license:             ISC+license-file:        LICENSE+synopsis:            QuickCheck instance for 'NonEmpty'+description:         QuickCheck instance for 'NonEmpty'.+Homepage:            http://github.com/blackheaven/nonempty-wrapper/nonempty-wrapper-quickcheck+tested-with:         GHC==9.2.2, GHC==9.0.2, GHC==8.10.7++library+  default-language:   Haskell2010+  build-depends:+        base == 4.*+      , QuickCheck == 2.*+      , nonempty-wrapper >= 0.1.0.0 && < 1+  hs-source-dirs: src+  exposed-modules:+      Test.QuickCheck.Instances.NonEmpty+  other-modules:+      Paths_nonempty_wrapper_quickcheck+  autogen-modules:+      Paths_nonempty_wrapper_quickcheck+  default-extensions:+      DataKinds+      DefaultSignatures+      DeriveAnyClass+      DeriveGeneric+      DerivingStrategies+      DerivingVia+      DuplicateRecordFields+      FlexibleContexts+      GADTs+      GeneralizedNewtypeDeriving+      KindSignatures+      LambdaCase+      OverloadedLists+      OverloadedStrings+      RankNTypes+      RecordWildCards+      ScopedTypeVariables+      TypeApplications+      TypeFamilies+      TypeOperators+  ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wpartial-fields -Wredundant-constraints
+ src/Test/QuickCheck/Instances/NonEmpty.hs view
@@ -0,0 +1,42 @@+{-# LANGUAGE UndecidableInstances #-}+{-# OPTIONS_GHC -fno-warn-orphans #-}++-- |+-- Module        : Test.QuickCheck.Instances.NonEmpty+-- Copyright     : Gautier DI FOLCO+-- License       : BSD2+--+-- Maintainer    : Gautier DI FOLCO <gautier.difolco@gmail.com>+-- Stability     : Unstable+-- Portability   : GHC+--+-- QuickCheck's 'Arbitrary' instance for 'NonEmpty'.+module Test.QuickCheck.Instances.NonEmpty+  ( Arbitrary (..),+  )+where++import Data.NonEmpty+import Data.Proxy+import Test.QuickCheck hiding (getNonEmpty)+import Data.Maybe (maybeToList)++instance+  ( Arbitrary a,+    Semigroup a,+    NonEmptySingleton a,+    NonEmptyFromContainer a,+    Arbitrary (NonEmptySingletonElement a)+  ) =>+  Arbitrary (NonEmpty a)+  where+  arbitrary =+    (<|)+      <$> fmap (singleton $ Proxy @a) arbitrary+      <*> arbitrary++  shrink xs =+    [ xs''+      | xs' <- shrink $ getNonEmpty xs,+        xs'' <- maybeToList $ nonEmpty xs'+    ]