diff --git a/src/Data/Chimera/Internal.hs b/src/Data/Chimera/Internal.hs index fea0ea3..e82fdf1 100644 --- a/src/Data/Chimera/Internal.hs +++ b/src/Data/Chimera/Internal.hs @@ -3,11 +3,9 @@ {-# LANGUAGE DeriveTraversable #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-} -{-# LANGUAGE LambdaCase #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE PolyKinds #-} {-# LANGUAGE ScopedTypeVariables #-} -{-# LANGUAGE TupleSections #-} {-# LANGUAGE TypeApplications #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE ViewPatterns #-} @@ -518,17 +516,6 @@ toInfinite = foldr (:<) foldr :: G.Vector v a => (a -> b -> b) -> Chimera v a -> b foldr f (Chimera vs) = F.foldr (flip $ G.foldr f) undefined vs -measureOff :: Int -> [a] -> Either Int ([a], [a]) -measureOff n - | n <= 0 = Right . ([],) - | otherwise = go n - where - go m [] = Left m - go 1 (x : xs) = Right ([x], xs) - go m (x : xs) = case go (m - 1) xs of - l@Left {} -> l - Right (xs', xs'') -> Right (x : xs', xs'') - measureOffVector :: G.Vector v a => Int -> v a -> Either Int (v a, v a) measureOffVector n xs | n <= l = Right (G.splitAt n xs) @@ -547,19 +534,7 @@ fromListWithDef -> [a] -- ^ Prefix -> Chimera v a -fromListWithDef a = Chimera . fromListN (bits + 1) . go0 - where - go0 = \case - [] -> G.singleton a : map (\k -> G.replicate (1 `shiftL` k) a) [0 .. bits - 1] - x : xs -> G.singleton x : go 0 xs - - go k xs = case measureOff kk xs of - Left l -> - G.fromListN kk (xs ++ replicate l a) - : map (\n -> G.replicate (1 `shiftL` n) a) [k + 1 .. bits - 1] - Right (ys, zs) -> G.fromListN kk ys : go (k + 1) zs - where - kk = 1 `shiftL` k +fromListWithDef a as = fromInfinite (Inf.prependList as (Inf.repeat a)) -- | Create a stream of values from a given infinite list. --