mirror of
https://github.com/jtdaugherty/brick.git
synced 2024-11-26 09:06:56 +03:00
List: add instance Splittable Seq
Add an instance of Splittable for Data.Sequence.Seq, and QuickCheck properties for it. Add lower bound containers >= 0.5.7, being the version at which the Semigroup instance was introduced.
This commit is contained in:
parent
8db170a02b
commit
f23b6b1dba
@ -94,7 +94,7 @@ library
|
||||
directory >= 1.2.5.0,
|
||||
dlist,
|
||||
filepath,
|
||||
containers,
|
||||
containers >= 0.5.7,
|
||||
microlens >= 0.3.0.0,
|
||||
microlens-th,
|
||||
microlens-mtl,
|
||||
|
@ -79,6 +79,7 @@ import Data.Foldable (find, toList)
|
||||
import Data.List.NonEmpty (NonEmpty((:|)))
|
||||
import Data.Maybe (fromMaybe)
|
||||
import Data.Semigroup (Semigroup, (<>), sconcat)
|
||||
import qualified Data.Sequence as Seq
|
||||
import Graphics.Vty (Event(..), Key(..), Modifier(..))
|
||||
import qualified Data.Vector as V
|
||||
import GHC.Generics (Generic)
|
||||
@ -140,6 +141,11 @@ class Splittable t where
|
||||
|
||||
-- | Slice the structure. Equivalent to @(take n . drop i) xs@,
|
||||
-- therefore total.
|
||||
--
|
||||
-- The default implementation applies 'splitAt' two times: first
|
||||
-- to drop elements leading up to the slice, and again to drop
|
||||
-- elements after the slice.
|
||||
--
|
||||
slice :: Int {- ^ start index -} -> Int {- ^ length -} -> t a -> t a
|
||||
slice i n = fst . splitAt n . snd . splitAt i
|
||||
|
||||
@ -147,6 +153,10 @@ class Splittable t where
|
||||
instance Splittable V.Vector where
|
||||
splitAt = V.splitAt
|
||||
|
||||
-- | /O(log(min(i,n-i)))/ 'splitAt'.
|
||||
instance Splittable Seq.Seq where
|
||||
splitAt = Seq.splitAt
|
||||
|
||||
|
||||
handleListEvent
|
||||
:: (Foldable t, Splittable t, Ord n)
|
||||
|
@ -14,6 +14,7 @@ import Data.Maybe (isNothing)
|
||||
import Data.Monoid (Endo(..))
|
||||
import Data.Semigroup (Semigroup((<>)))
|
||||
|
||||
import qualified Data.Sequence as Seq
|
||||
import qualified Data.Vector as V
|
||||
import Lens.Micro
|
||||
import Test.QuickCheck
|
||||
@ -272,6 +273,12 @@ prop_splitAtLength_Vector = splitAtLength . V.fromList
|
||||
prop_splitAtAppend_Vector :: (Eq a) => [a] -> Int -> Bool
|
||||
prop_splitAtAppend_Vector = splitAtAppend . V.fromList
|
||||
|
||||
prop_splitAtLength_Seq :: [a] -> Int -> Bool
|
||||
prop_splitAtLength_Seq = splitAtLength . Seq.fromList
|
||||
|
||||
prop_splitAtAppend_Seq :: (Eq a) => [a] -> Int -> Bool
|
||||
prop_splitAtAppend_Seq = splitAtAppend . Seq.fromList
|
||||
|
||||
|
||||
return []
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user