mono-traversable 0.6.2 → 0.6.3
raw patch · 4 files changed
+17/−3 lines, 4 files
Files
- README.md +1/−1
- mono-traversable.cabal +1/−1
- src/Data/NonNull.hs +4/−0
- test/Spec.hs +11/−1
README.md view
@@ -3,7 +3,7 @@ Type classes for mapping, folding, and traversing monomorphic containers. Contains even more experimental code for abstracting containers and sequences. -A polymorphin container is one such as list which has a type variable `[a]`+A polymorphic container is one such as list which has a type variable `[a]` A monomorphic container is one such as Text which has a type `Text` that does not expose the underlying characters. Adding instances
mono-traversable.cabal view
@@ -1,5 +1,5 @@ name: mono-traversable-version: 0.6.2+version: 0.6.3 synopsis: Type classes for mapping, folding, and traversing monomorphic containers description: Monomorphic variants of the Functor, Foldable, and Traversable typeclasses. If you understand Haskell's basic typeclasses, you understand mono-traversable. In addition to what you are used to, it adds on an IsSequence typeclass and has code for marking data structures as non-empty. homepage: https://github.com/snoyberg/mono-traversable
src/Data/NonNull.hs view
@@ -37,6 +37,7 @@ , minimum , minimumBy , (<|)+ , toMinList ) where import Prelude hiding (head, tail, init, last, reverse, seq, filter, replicate, maximum, minimum)@@ -72,6 +73,9 @@ fromNonEmpty :: IsSequence seq => NE.NonEmpty (Element seq) -> NonNull seq fromNonEmpty = nonNull . fromList . NE.toList {-# INLINE fromNonEmpty #-}++toMinList :: NE.NonEmpty a -> NonNull [a] +toMinList ne = fromNonEmpty ne -- | Like cons, prepends an element. -- However, the prepend is to a Nullable, creating a 'NonNull'
test/Spec.hs view
@@ -1,11 +1,12 @@ {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE ViewPatterns #-}+{-# LANGUAGE ScopedTypeVariables #-} module Spec where import Test.Hspec import Test.Hspec.QuickCheck-import Test.QuickCheck (Arbitrary)+import Test.QuickCheck (Arbitrary(..)) import Data.MonoTraversable import Data.Text (Text) import qualified Data.Text as T@@ -32,7 +33,11 @@ import qualified Control.Foldl as Foldl import Data.Int (Int64) import Data.ByteVector+import Control.Monad (liftM2) +instance Arbitrary a => Arbitrary (NE.NonEmpty a) where+ arbitrary = liftM2 (NE.:|) arbitrary arbitrary+ main :: IO () main = hspec $ do describe "cnull" $ do@@ -123,6 +128,11 @@ test "strict Text" T.empty test "lazy Text" TL.empty describe "NonNull" $ do+ describe "fromNonEmpty" $ do+ prop "toMinList" $ \(ne :: NE.NonEmpty Int) ->+ let m = NN.toMinList ne+ in NE.toList ne `shouldBe` NN.toNullable m+ let test' forceTyp typ dummy = describe typ $ do prop "head" $ \x xs -> let nn = forceTyp $ NN.ncons x (fromList xs `asTypeOf` dummy)