{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ExplicitForAll #-}
{-# LANGUAGE FlexibleContexts #-}
{-# OPTIONS_GHC -fno-warn-duplicate-exports #-}

-- |
-- Module      : Data.Massiv.Vector
-- Copyright   : (c) Alexey Kuleshevich 2020-2022
-- License     : BSD3
-- Maintainer  : Alexey Kuleshevich <lehins@yandex.ru>
-- Stability   : experimental
-- Portability : non-portable
module Data.Massiv.Vector (
  Vector,
  MVector,

  -- * Accessors

  -- *** Size
  slength,
  maxLinearSize,
  size,
  isNull,
  isNotNull,

  -- *** Indexing
  (!?),
  (!),
  index,
  index',
  head',
  shead',
  last',

  -- *** Monadic Indexing
  indexM,
  headM,
  sheadM,
  lastM,
  unconsM,
  unsnocM,

  -- ** Slicing
  slice,
  slice',
  sliceM,
  sslice,
  sliceAt,
  sliceAt',
  sliceAtM,

  -- *** Init
  init,
  init',
  initM,

  -- *** Tail
  tail,
  tail',
  tailM,

  -- *** Take
  take,
  take',
  takeM,
  takeWhile,
  stake,

  -- *** Drop
  drop,
  dropWhile,
  drop',
  dropM,
  sdrop,

  -- * Construction

  -- ** Initialization
  empty,
  sempty,
  singleton,
  ssingleton,
  cons,
  snoc,
  A.replicate,
  sreplicate,
  generate,
  sgenerate,
  -- , iterateN
  -- , iiterateN
  siterate,
  siterateN,

  -- ** Monadic initialization
  sreplicateM,
  sgenerateM,
  siterateNM,
  -- , create
  -- , createT

  -- ** Unfolding
  sunfoldr,
  sunfoldrM,
  sunfoldrN,
  sunfoldrNM,
  sunfoldrExactN,
  sunfoldrExactNM,
  -- , constructN
  -- , constructrN

  -- ** Enumeration
  (...),
  (..:),
  enumFromN,
  senumFromN,
  enumFromStepN,
  senumFromStepN,

  -- ** Concatenation

  -- , consS -- cons
  -- , snocS -- snoc
  sappend, -- (++)
  sconcat, -- concat
  -- -- ** Restricitng memory usage
  -- , force
  -- -- * Modifying
  -- -- ** Bulk updates
  -- , (//)
  -- , update_
  -- -- ** Accumulations
  -- , accum
  -- , accumulate_
  -- -- ** Permutations
  -- , reverse
  -- , backpermute
  -- -- ** Manifest updates
  -- , modify
  -- -- * Elementwise
  -- -- ** Mapping
  smap,
  simap,
  -- , sconcatMap

  -- ** Monadic mapping
  straverse,
  sitraverse,
  smapM,
  smapM_,
  simapM,
  simapM_,
  sforM,
  sforM_,
  siforM,
  siforM_,

  -- ** Zipping
  szip,
  szip3,
  szip4,
  szip5,
  szip6,
  szipWith,
  szipWith3,
  szipWith4,
  szipWith5,
  szipWith6,
  sizipWith,
  sizipWith3,
  sizipWith4,
  sizipWith5,
  sizipWith6,

  -- ** Monadic zipping
  szipWithM,
  szipWith3M,
  szipWith4M,
  szipWith5M,
  szipWith6M,
  sizipWithM,
  sizipWith3M,
  sizipWith4M,
  sizipWith5M,
  sizipWith6M,
  szipWithM_,
  szipWith3M_,
  szipWith4M_,
  szipWith5M_,
  szipWith6M_,
  sizipWithM_,
  sizipWith3M_,
  sizipWith4M_,
  sizipWith5M_,
  sizipWith6M_,

  -- * Predicates

  -- ** Filtering
  sfilter,
  sifilter,
  sfilterM,
  sifilterM,
  -- , uniq -- sunique?
  smapMaybe,
  smapMaybeM,
  scatMaybes,
  simapMaybe,
  simapMaybeM,
  -- , stakeWhile
  -- , sdropWhile
  -- -- ** Partitioning
  -- , partition
  -- , unstablePartition
  -- , partitionWith
  -- , span
  -- , break
  -- -- ** Searching
  -- , elem
  -- , notElem
  -- , find
  findIndex,
  -- , findIndices
  -- , elemIndex
  -- , elemIndices

  -- * Folding
  sfoldl,
  sfoldlM,
  sfoldlM_,
  sifoldl,
  sifoldlM,
  sifoldlM_,
  sfoldl1',
  sfoldl1M,
  sfoldl1M_,

  -- ** Specialized folds
  sor,
  sand,
  sall,
  sany,
  ssum,
  sproduct,
  smaximum',
  smaximumM,
  -- , maximumBy
  sminimum',
  sminimumM,
  -- , minimumBy
  -- , minIndex
  -- , minIndexBy
  -- , maxIndex
  -- , maxIndexBy

  -- ** Scanning
  sprescanl,
  spostscanl,
  spostscanlAcc,
  sscanl,
  sscanl1,
  -- sprescanr,
  -- spostscanr,
  -- sscanr,
  -- sscanr1,

  -- * Conversions

  -- ** Lists
  stoList,
  fromList,
  sfromList,
  sfromListN,

  -- * Computation
  compute,
  computeS,
  computeIO,
  computePrimM,
  computeAs,
  computeProxy,
  computeSource,
  computeWithStride,
  computeWithStrideAs,
  clone,
  convert,
  convertAs,
  convertProxy,

  -- ** Re-exports
  module Data.Massiv.Core,
  module Data.Massiv.Array.Delayed,
  module Data.Massiv.Array.Manifest,
  module Data.Massiv.Array.Mutable,
) where

import Control.Monad hiding (filterM, replicateM)
import Data.Coerce
import Data.Massiv.Array.Delayed
import Data.Massiv.Array.Delayed.Pull
import Data.Massiv.Array.Delayed.Push
import Data.Massiv.Array.Delayed.Stream
import Data.Massiv.Array.Manifest
import Data.Massiv.Array.Manifest.Internal
import Data.Massiv.Array.Manifest.List (fromList)
import Data.Massiv.Array.Mutable
import Data.Massiv.Array.Ops.Construct
import qualified Data.Massiv.Array.Ops.Construct as A (replicate)
import Data.Massiv.Core
import Data.Massiv.Core.Common
import qualified Data.Massiv.Vector.Stream as S
import Data.Massiv.Vector.Unsafe
import Data.Maybe
import Prelude hiding (
  drop,
  dropWhile,
  init,
  length,
  null,
  replicate,
  splitAt,
  tail,
  take,
  takeWhile,
 )

-- ========= --
-- Accessors --
-- ========= --

------------------------
-- Length information --
------------------------

-- | /O(1)/ - Get the length of a `Stream` array, but only if it is known exactly in
-- constant time without looking at any of the elements in the array.
--
-- /Related/: `maxLinearSize`, `size`, `elemsCount` and `totalElem`
--
-- ==== __Examples__
--
-- >>> slength $ sfromList []
-- Nothing
-- >>> slength $ sreplicate 5 ()
-- Just (Sz1 5)
-- >>> slength $ makeArrayLinearR D Seq (Sz1 5) id
-- Just (Sz1 5)
-- >>> slength $ sunfoldr (\x -> Just (x, x)) (0 :: Int)
-- Nothing
-- >>> slength $ sunfoldrN 10 (\x -> Just (x, x)) (0 :: Int)
-- Nothing
-- >>> slength $ sunfoldrExactN 10 (\x -> (x, x)) (0 :: Int)
-- Just (Sz1 10)
--
-- /__Similar__/:
--
-- [@Data.Foldable.`Data.Foldable.length`@] For some data structures, like a list for
-- example, it is an /O(n)/ operation, because there is a need to evaluate the full spine
-- and possibly even the elements in order to get the full length. With `Stream` vectors
-- that is not always the case.
--
-- [@Data.Vector.Generic.`Data.Vector.Generic.length`@] In the vector package this
-- function will always break fusion, unless it is the only operation that is applied to
-- the vector.
--
-- @since 0.5.0
slength
  :: forall r ix e
   . Stream r ix e
  => Array r ix e
  -> Maybe Sz1
slength :: forall r ix e. Stream r ix e => Array r ix e -> Maybe Sz1
slength Array r ix e
v =
  case forall (m :: * -> *) e. Steps m e -> LengthHint
stepsSize (forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
toStream Array r ix e
v) of
    LengthExact Sz1
sz -> forall a. a -> Maybe a
Just Sz1
sz
    LengthHint
_ -> forall a. Maybe a
Nothing
{-# INLINE slength #-}

--------------
-- Indexing --
--------------

-- | /O(1)/ - Get the first element of a `Source` vector. Throws an error on empty.
--
-- /Related/: 'shead'', `headM`, `sheadM`, `unconsM`.
--
-- ==== __Examples__
--
-- >>> head' (Ix1 10 ..: 10000000000000)
-- 10
--
-- /__Similar__/:
--
-- [@Data.List.`Data.List.head`@] Also constant time and partial. Fusion is broken if
-- there other consumers of the list.
--
-- [@Data.Vector.Generic.`Data.Vector.Generic.head`@] Also constant time and partial. Will
-- cause materialization of the full vector if any other function is applied to the vector.
--
-- @since 0.5.0
head'
  :: forall r e
   . (HasCallStack, Source r e)
  => Vector r e
  -> e
head' :: forall r e. (HasCallStack, Source r e) => Vector r e -> e
head' = forall a. HasCallStack => Either SomeException a -> a
throwEither forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r e (m :: * -> *).
(Source r e, MonadThrow m) =>
Vector r e -> m e
headM
{-# INLINE head' #-}

-- | /O(1)/ - Get the first element of a `Source` vector.
--
-- /Related/: 'head'', 'shead'', `sheadM`, `unconsM`.
--
-- /__Throws Exceptions__/: `SizeEmptyException` when array is empty
--
-- ==== __Examples__
--
-- >>> headM (Ix1 10 ..: 10000000000000)
-- 10
-- >>> headM (Ix1 10 ..: 10000000000000) :: Maybe Int
-- Just 10
-- >>> headM (empty :: Array D Ix1 Int) :: Maybe Int
-- Nothing
-- >>> either show (const "") $ headM (Ix1 10 ..: 10)
-- "SizeEmptyException: (Sz1 0) corresponds to an empty array"
--
-- /__Similar__/:
--
-- [@Data.Maybe.`Data.Maybe.listToMaybe`@] It also a safe way to get the head of the list,
-- except it is restricted to `Maybe`
--
-- @since 0.5.0
headM
  :: forall r e m
   . (Source r e, MonadThrow m)
  => Vector r e
  -> m e
headM :: forall r e (m :: * -> *).
(Source r e, MonadThrow m) =>
Vector r e -> m e
headM Vector r e
v
  | forall ix r e. (Index ix, Size r) => Array r ix e -> Int
elemsCount Vector r e
v forall a. Eq a => a -> a -> Bool
== Int
0 = forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwM forall a b. (a -> b) -> a -> b
$ forall ix. Index ix => Sz ix -> SizeException
SizeEmptyException (forall r ix e. Size r => Array r ix e -> Sz ix
size Vector r e
v)
  | Bool
otherwise = forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ forall r e ix. (Source r e, Index ix) => Array r ix e -> Int -> e
unsafeLinearIndex Vector r e
v Int
0
{-# INLINE headM #-}

-- | /O(1)/ - Get the first element of a `Stream` vector. Throws an error on empty.
--
-- /Related/: 'head'', `headM`, `sheadM`, `unconsM`.
--
-- ==== __Examples__
--
-- >>> shead' $ sunfoldr (\x -> Just (x, x)) (0 :: Int)
-- 0
-- >>> shead' (Ix1 3 ... 5)
-- 3
--
-- @since 0.5.0
shead'
  :: forall r e
   . (HasCallStack, Stream r Ix1 e)
  => Vector r e
  -> e
shead' :: forall r e. (HasCallStack, Stream r Int e) => Vector r e -> e
shead' = forall a. HasCallStack => Either SomeException a -> a
throwEither forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r e (m :: * -> *).
(Stream r Int e, MonadThrow m) =>
Vector r e -> m e
sheadM
{-# INLINE shead' #-}

-- | /O(1)/ - Get the first element of a `Stream` vector.
--
-- /Related/: 'head'', 'shead'', `headM`, `unconsM`.
--
-- /__Throws Exceptions__/: `SizeEmptyException`
--
-- ==== __Examples__
--
-- >>> maybe 101 id $ sheadM (empty :: Vector D Int)
-- 101
-- >>> maybe 101 id $ sheadM (singleton 202 :: Vector D Int)
-- 202
-- >>> sheadM $ sunfoldr (\x -> Just (x, x)) (0 :: Int)
-- 0
-- >>> x <- sheadM $ sunfoldr (\_ -> Nothing) (0 :: Int)
-- *** Exception: SizeEmptyException: (Sz1 0) corresponds to an empty array
--
-- @since 0.5.0
sheadM
  :: forall r e m
   . (Stream r Ix1 e, MonadThrow m)
  => Vector r e
  -> m e
sheadM :: forall r e (m :: * -> *).
(Stream r Int e, MonadThrow m) =>
Vector r e -> m e
sheadM Vector r e
v =
  case forall a. Id a -> a
S.unId (forall (m :: * -> *) a. Monad m => Steps m a -> m (Maybe a)
S.headMaybe (forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
toStream Vector r e
v)) of
    Maybe e
Nothing -> forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwM forall a b. (a -> b) -> a -> b
$ forall ix. Index ix => Sz ix -> SizeException
SizeEmptyException (forall ix. Index ix => Sz ix
zeroSz :: Sz1)
    Just e
e -> forall (f :: * -> *) a. Applicative f => a -> f a
pure e
e
{-# INLINE sheadM #-}

-- | /O(1)/ - Take one element off of the `Source` vector from the left side, as well as
-- the remaining part of the vector in delayed `D` representation.
--
-- /Related/: 'head'', 'shead'', `headM`, `sheadM`, `cons`
--
-- /__Throws Exceptions__/: `SizeEmptyException`
--
-- ==== __Examples__
--
-- >>> unconsM (fromList Seq [1,2,3] :: Array P Ix1 Int)
-- (1,Array P Seq (Sz1 2)
--   [ 2, 3 ])
--
-- /__Similar__/:
--
-- [@Data.List.`Data.List.uncons`@] Same concept, except it is restricted to `Maybe` instead of
-- the more general `MonadThrow`
--
-- @since 0.3.0
unconsM
  :: forall r e m
   . (MonadThrow m, Source r e)
  => Vector r e
  -> m (e, Vector r e)
unconsM :: forall r e (m :: * -> *).
(MonadThrow m, Source r e) =>
Vector r e -> m (e, Vector r e)
unconsM Vector r e
arr
  | Int
0 forall a. Eq a => a -> a -> Bool
== forall ix. Index ix => Sz ix -> Int
totalElem Sz1
sz = forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwM forall a b. (a -> b) -> a -> b
$ forall ix. Index ix => Sz ix -> SizeException
SizeEmptyException Sz1
sz
  | Bool
otherwise = forall (f :: * -> *) a. Applicative f => a -> f a
pure (forall r e ix. (Source r e, Index ix) => Array r ix e -> Int -> e
unsafeLinearIndex Vector r e
arr Int
0, forall r e ix.
(Source r e, Index ix) =>
Int -> Sz1 -> Array r ix e -> Array r Int e
unsafeLinearSlice Int
1 (forall ix. ix -> Sz ix
SafeSz (forall ix. Sz ix -> ix
unSz Sz1
sz forall a. Num a => a -> a -> a
- Int
1)) Vector r e
arr)
  where
    !sz :: Sz1
sz = forall r ix e. Size r => Array r ix e -> Sz ix
size Vector r e
arr
{-# INLINE unconsM #-}

-- | /O(1)/ - Take one element off of the vector from the right side, as well as the
-- remaining part of the vector.
--
-- /Related/: 'last'', `lastM`, `snoc`
--
-- /__Throws Exceptions__/: `SizeEmptyException`
--
-- ==== __Examples__
--
-- >>> unsnocM (fromList Seq [1,2,3] :: Array P Ix1 Int)
-- (Array P Seq (Sz1 2)
--   [ 1, 2 ],3)
--
-- @since 0.3.0
unsnocM
  :: forall r e m
   . (MonadThrow m, Source r e)
  => Vector r e
  -> m (Vector r e, e)
unsnocM :: forall r e (m :: * -> *).
(MonadThrow m, Source r e) =>
Vector r e -> m (Vector r e, e)
unsnocM Vector r e
arr
  | Int
0 forall a. Eq a => a -> a -> Bool
== forall ix. Index ix => Sz ix -> Int
totalElem Sz1
sz = forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwM forall a b. (a -> b) -> a -> b
$ forall ix. Index ix => Sz ix -> SizeException
SizeEmptyException Sz1
sz
  | Bool
otherwise = forall (f :: * -> *) a. Applicative f => a -> f a
pure (forall r e ix.
(Source r e, Index ix) =>
Int -> Sz1 -> Array r ix e -> Array r Int e
unsafeLinearSlice Int
0 (forall ix. ix -> Sz ix
SafeSz Int
k) Vector r e
arr, forall r e ix. (Source r e, Index ix) => Array r ix e -> Int -> e
unsafeLinearIndex Vector r e
arr Int
k)
  where
    !sz :: Sz1
sz = forall r ix e. Size r => Array r ix e -> Sz ix
size Vector r e
arr
    !k :: Int
k = forall ix. Sz ix -> ix
unSz Sz1
sz forall a. Num a => a -> a -> a
- Int
1
{-# INLINE unsnocM #-}

-- | /O(1)/ - Get the last element of a `Source` vector. Throws an error on empty.
--
-- /Related/: `lastM`, `unsnocM`
--
-- ==== __Examples__
--
-- >>> last' (Ix1 10 ... 10000000000000)
-- 10000000000000
--
-- /__Similar__/:
--
-- [@Data.List.`Data.List.last`@] Also partial, but it has /O(n)/ complexity. Fusion is
-- broken if there other consumers of the list.
--
-- [@Data.Vector.Generic.`Data.Vector.Generic.last`@] Also constant time and partial. Will
-- cause materialization of the full vector if any other function is applied to the vector.
--
-- @since 0.5.0
last' :: forall r e. (HasCallStack, Source r e) => Vector r e -> e
last' :: forall r e. (HasCallStack, Source r e) => Vector r e -> e
last' = forall a. HasCallStack => Either SomeException a -> a
throwEither forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r e (m :: * -> *).
(Source r e, MonadThrow m) =>
Vector r e -> m e
lastM
{-# INLINE last' #-}

-- | /O(1)/ - Get the last element of a `Source` vector.
--
-- /Related/: 'last'', `unsnocM`
--
-- /__Throws Exceptions__/: `SizeEmptyException`
--
-- ==== __Examples__
--
-- >>> lastM (Ix1 10 ... 10000000000000)
-- 10000000000000
-- >>> lastM (Ix1 10 ... 10000000000000) :: Maybe Int
-- Just 10000000000000
-- >>> either show (const "") $ lastM (fromList Seq [] :: Array P Ix1 Int)
-- "SizeEmptyException: (Sz1 0) corresponds to an empty array"
--
-- @since 0.5.0
lastM :: forall r e m. (Source r e, MonadThrow m) => Vector r e -> m e
lastM :: forall r e (m :: * -> *).
(Source r e, MonadThrow m) =>
Vector r e -> m e
lastM Vector r e
v
  | Int
k forall a. Eq a => a -> a -> Bool
== Int
0 = forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwM forall a b. (a -> b) -> a -> b
$ forall ix. Index ix => Sz ix -> SizeException
SizeEmptyException (forall r ix e. Size r => Array r ix e -> Sz ix
size Vector r e
v)
  | Bool
otherwise = forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ forall r e ix. (Source r e, Index ix) => Array r ix e -> Int -> e
unsafeLinearIndex Vector r e
v (Int
k forall a. Num a => a -> a -> a
- Int
1)
  where
    k :: Int
k = forall ix. Sz ix -> ix
unSz (forall r ix e. Size r => Array r ix e -> Sz ix
size Vector r e
v)
{-# INLINE lastM #-}

-- | /O(1)/ - Take a slice of a `Source` vector. Never fails, instead adjusts the indices.
--
-- ==== __Examples__
--
-- >>> slice 10 5 (Ix1 0 ... 10000000000000)
-- Array D Seq (Sz1 5)
--   [ 10, 11, 12, 13, 14 ]
-- >>> slice (-10) 5 (Ix1 0 ... 10000000000000)
-- Array D Seq (Sz1 5)
--   [ 0, 1, 2, 3, 4 ]
-- >>> slice 9999999999998 50 (Ix1 0 ... 10000000000000)
-- Array D Seq (Sz1 3)
--   [ 9999999999998, 9999999999999, 10000000000000 ]
--
-- @since 0.5.0
slice :: forall r e. Source r e => Ix1 -> Sz1 -> Vector r e -> Vector r e
slice :: forall r e. Source r e => Int -> Sz1 -> Vector r e -> Vector r e
slice !Int
i (Sz Int
k) Vector r e
v = forall r e ix.
(Source r e, Index ix) =>
Int -> Sz1 -> Array r ix e -> Array r Int e
unsafeLinearSlice Int
i' Sz1
newSz Vector r e
v
  where
    !i' :: Int
i' = forall a. Ord a => a -> a -> a
min Int
n (forall a. Ord a => a -> a -> a
max Int
0 Int
i)
    !newSz :: Sz1
newSz = forall ix. ix -> Sz ix
SafeSz (forall a. Ord a => a -> a -> a
min (Int
n forall a. Num a => a -> a -> a
- Int
i') Int
k)
    Sz Int
n = forall r ix e. Size r => Array r ix e -> Sz ix
size Vector r e
v
{-# INLINE slice #-}

-- | /O(1)/ - Take a slice of a `Source` vector. Throws an error on incorrect indices.
--
-- ==== __Examples__
--
-- >>> slice' 10 5 (Ix1 0 ... 100)
-- Array D Seq (Sz1 5)
--   [ 10, 11, 12, 13, 14 ]
-- >>> slice' 9999999999998 3 (Ix1 0 ... 10000000000000)
-- Array D Seq (Sz1 3)
--   [ 9999999999998, 9999999999999, 10000000000000 ]
--
-- @since 0.5.0
slice' :: forall r e. (HasCallStack, Source r e) => Ix1 -> Sz1 -> Vector r e -> Vector r e
slice' :: forall r e.
(HasCallStack, Source r e) =>
Int -> Sz1 -> Vector r e -> Vector r e
slice' Int
i Sz1
k = forall a. HasCallStack => Either SomeException a -> a
throwEither forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r e (m :: * -> *).
(Source r e, MonadThrow m) =>
Int -> Sz1 -> Vector r e -> m (Vector r e)
sliceM Int
i Sz1
k
{-# INLINE slice' #-}

-- | /O(1)/ - Take a slice of a `Source` vector. Throws an error on incorrect indices.
--
-- /__Throws Exceptions__/: `SizeSubregionException`
--
-- ==== __Examples__
--
-- >>> sliceM 10 5 (Ix1 0 ... 100)
-- Array D Seq (Sz1 5)
--   [ 10, 11, 12, 13, 14 ]
-- >>> sliceM (-10) 5 (Ix1 0 ... 100)
-- *** Exception: SizeSubregionException: (Sz1 101) is to small for -10 (Sz1 5)
-- >>> sliceM 98 50 (Ix1 0 ... 100)
-- *** Exception: SizeSubregionException: (Sz1 101) is to small for 98 (Sz1 50)
-- >>> sliceM 9999999999998 3 (Ix1 0 ... 10000000000000)
-- Array D Seq (Sz1 3)
--   [ 9999999999998, 9999999999999, 10000000000000 ]
--
-- @since 0.5.0
sliceM
  :: forall r e m
   . (Source r e, MonadThrow m)
  => Ix1
  -- ^ Starting index
  -> Sz1
  -- ^ Number of elements to take from the Source vector
  -> Vector r e
  -- ^ Source vector to take a slice from
  -> m (Vector r e)
sliceM :: forall r e (m :: * -> *).
(Source r e, MonadThrow m) =>
Int -> Sz1 -> Vector r e -> m (Vector r e)
sliceM Int
i newSz :: Sz1
newSz@(Sz Int
k) Vector r e
v
  | Int
i forall a. Ord a => a -> a -> Bool
>= Int
0 Bool -> Bool -> Bool
&& Int
k forall a. Ord a => a -> a -> Bool
<= Int
n forall a. Num a => a -> a -> a
- Int
i = forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ forall r e ix.
(Source r e, Index ix) =>
Int -> Sz1 -> Array r ix e -> Array r Int e
unsafeLinearSlice Int
i Sz1
newSz Vector r e
v
  | Bool
otherwise = forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwM forall a b. (a -> b) -> a -> b
$ forall ix. Index ix => Sz ix -> ix -> Sz ix -> SizeException
SizeSubregionException Sz1
sz Int
i Sz1
newSz
  where
    sz :: Sz1
sz@(Sz Int
n) = forall r ix e. Size r => Array r ix e -> Sz ix
size Vector r e
v
{-# INLINE sliceM #-}

-- | Take a slice of a `Stream` vector. Never fails, instead adjusts the indices.
--
-- ==== __Examples__
--
-- >>> sslice 10 5 (Ix1 0 ... 10000000000000)
-- Array DS Seq (Sz1 5)
--   [ 10, 11, 12, 13, 14 ]
-- >>> sslice 10 5 (sfromList [0 :: Int .. ])
-- Array DS Seq (Sz1 5)
--   [ 10, 11, 12, 13, 14 ]
-- >>> sslice (-10) 5 (Ix1 0 ... 10000000000000)
-- Array DS Seq (Sz1 5)
--   [ 0, 1, 2, 3, 4 ]
--
-- Unlike `slice` it has to iterate through each element until the staring index is reached,
-- therefore something like @sslice 9999999999998 50 (Ix1 0 ... 10000000000000)@ will not
-- be feasable.
--
-- >>> import System.Timeout (timeout)
-- >>> let smallArr = sslice 9999999999998 50 (Ix1 0 ... 10000000000000)
-- >>> timeout 500000 (computeIO smallArr :: IO (Array P Ix1 Int))
-- Nothing
--
-- @since 0.5.0
sslice
  :: forall r e
   . Stream r Ix1 e
  => Ix1
  -- ^ Starting index
  -> Sz1
  -- ^ Number of elements to take from the stream vector
  -> Vector r e
  -- ^ Stream vector to take a slice from
  -> Vector DS e
sslice :: forall r e.
Stream r Int e =>
Int -> Sz1 -> Vector r e -> Vector DS e
sslice !Int
i !Sz1
k = forall e. Steps Id e -> Vector DS e
fromSteps forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a.
Monad m =>
Int -> Sz1 -> Steps m a -> Steps m a
S.slice Int
i Sz1
k forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream
{-# INLINE sslice #-}

-- | /O(1)/ - Get a vector without the last element. Never fails.
--
-- ==== __Examples__
--
-- >>> import Data.Massiv.Array as A
-- >>> A.init (0 ..: 10)
-- Array D Seq (Sz1 9)
--   [ 0, 1, 2, 3, 4, 5, 6, 7, 8 ]
-- >>> A.init (empty :: Array D Ix1 Int)
-- Array D Seq (Sz1 0)
--   [  ]
--
-- @since 0.5.0
init :: forall r e. Source r e => Vector r e -> Vector r e
init :: forall r e. Source r e => Vector r e -> Vector r e
init Vector r e
v = forall r e ix.
(Source r e, Index ix) =>
Int -> Sz1 -> Array r ix e -> Array r Int e
unsafeLinearSlice Int
0 (forall ix. Index ix => ix -> Sz ix
Sz (coerce :: forall a b. Coercible a b => a -> b
coerce (forall r ix e. Size r => Array r ix e -> Sz ix
size Vector r e
v) forall a. Num a => a -> a -> a
- Int
1)) Vector r e
v
{-# INLINE init #-}

-- | /O(1)/ - Get a vector without the last element. Throws an error on empty
--
-- ==== __Examples__
--
-- >>> init' (0 ..: 10)
-- Array D Seq (Sz1 9)
--   [ 0, 1, 2, 3, 4, 5, 6, 7, 8 ]
--
-- @since 0.5.0
init' :: forall r e. (HasCallStack, Source r e) => Vector r e -> Vector r e
init' :: forall r e. (HasCallStack, Source r e) => Vector r e -> Vector r e
init' = forall a. HasCallStack => Either SomeException a -> a
throwEither forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r e (m :: * -> *).
(Source r e, MonadThrow m) =>
Vector r e -> m (Vector r e)
initM
{-# INLINE init' #-}

-- | /O(1)/ - Get a vector without the last element. Throws an error on empty
--
-- ==== __Examples__
--
-- >>> import Data.Massiv.Array as A
-- >>> initM (0 ..: 10)
-- Array D Seq (Sz1 9)
--   [ 0, 1, 2, 3, 4, 5, 6, 7, 8 ]
-- >>> maybe 0 A.sum $ initM (0 ..: 10)
-- 36
-- >>> maybe 0 A.sum $ initM (empty :: Array D Ix1 Int)
-- 0
--
-- @since 0.5.0
initM :: forall r e m. (Source r e, MonadThrow m) => Vector r e -> m (Vector r e)
initM :: forall r e (m :: * -> *).
(Source r e, MonadThrow m) =>
Vector r e -> m (Vector r e)
initM Vector r e
v = do
  forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (forall ix r e. (Index ix, Size r) => Array r ix e -> Int
elemsCount Vector r e
v forall a. Eq a => a -> a -> Bool
== Int
0) forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwM forall a b. (a -> b) -> a -> b
$ forall ix. Index ix => Sz ix -> SizeException
SizeEmptyException forall a b. (a -> b) -> a -> b
$ forall r ix e. Size r => Array r ix e -> Sz ix
size Vector r e
v
  forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ forall r e. Source r e => Vector r e -> Vector r e
unsafeInit Vector r e
v
{-# INLINE initM #-}

-- | /O(1)/ - Get a vector without the first element. Never fails
--
-- ==== __Examples__
--
-- >>> import Data.Massiv.Array as A
-- >>> A.tail (0 ..: 10)
-- Array D Seq (Sz1 9)
--   [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
-- >>> A.tail (empty :: Array D Ix1 Int)
-- Array D Seq (Sz1 0)
--   [  ]
--
-- @since 0.5.0
tail :: forall r e. Source r e => Vector r e -> Vector r e
tail :: forall r e. Source r e => Vector r e -> Vector r e
tail = forall r e. Source r e => Sz1 -> Vector r e -> Vector r e
drop forall ix. Index ix => Sz ix
oneSz
{-# INLINE tail #-}

-- | /O(1)/ - Get a vector without the first element. Throws an error on empty
--
-- ==== __Examples__
--
-- λ> tail' (0 ..: 10)
-- Array D Seq (Sz1 9)
--   [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
-- λ> tail' (empty :: Array D Ix1 Int)
-- Array D *** Exception: SizeEmptyException: (Sz1 0) corresponds to an empty array
--
-- @since 0.5.0
tail' :: forall r e. (HasCallStack, Source r e) => Vector r e -> Vector r e
tail' :: forall r e. (HasCallStack, Source r e) => Vector r e -> Vector r e
tail' = forall a. HasCallStack => Either SomeException a -> a
throwEither forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r e (m :: * -> *).
(Source r e, MonadThrow m) =>
Vector r e -> m (Vector r e)
tailM
{-# INLINE tail' #-}

-- | /O(1)/ - Get the vector without the first element. Throws an error on empty
--
-- ==== __Examples__
--
-- >>> import Data.Massiv.Array as A
-- >>> tailM (0 ..: 10)
-- Array D Seq (Sz1 9)
--   [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
-- >>> maybe 0 A.sum $ tailM (0 ..: 10)
-- 45
-- >>> maybe 0 A.sum $ tailM (empty :: Array D Ix1 Int)
-- 0
--
-- @since 0.5.0
tailM :: forall r e m. (Source r e, MonadThrow m) => Vector r e -> m (Vector r e)
tailM :: forall r e (m :: * -> *).
(Source r e, MonadThrow m) =>
Vector r e -> m (Vector r e)
tailM Vector r e
v = do
  forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (forall ix r e. (Index ix, Size r) => Array r ix e -> Int
elemsCount Vector r e
v forall a. Eq a => a -> a -> Bool
== Int
0) forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwM forall a b. (a -> b) -> a -> b
$ forall ix. Index ix => Sz ix -> SizeException
SizeEmptyException forall a b. (a -> b) -> a -> b
$ forall r ix e. Size r => Array r ix e -> Sz ix
size Vector r e
v
  forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ forall r e. Source r e => Vector r e -> Vector r e
unsafeTail Vector r e
v
{-# INLINE tailM #-}

-- | /O(1)/ - Take first @n@ elements from a vector. This function never fails and has
-- similar semantics as the `Data.List.take` for lists.
--
-- ==== __Examples__
--
-- >>> import Data.Massiv.Array as A
-- >>> A.take 5 (0 ..: 10)
-- Array D Seq (Sz1 5)
--   [ 0, 1, 2, 3, 4 ]
-- >>> A.take 0 (0 ..: 10)
-- Array D Seq (Sz1 0)
--   [  ]
-- >>> A.take 100 (0 ..: 10)
-- Array D Seq (Sz1 10)
--   [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
--
-- @since 0.5.0
take :: Source r e => Sz1 -> Vector r e -> Vector r e
take :: forall r e. Source r e => Sz1 -> Vector r e -> Vector r e
take Sz1
k = forall a b. (a, b) -> a
fst forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r e.
Source r e =>
Sz1 -> Vector r e -> (Vector r e, Vector r e)
sliceAt Sz1
k
{-# INLINE take #-}

-- | Slice a manifest vector in such a way that it will contain all initial elements that
-- satisfy the supplied predicate.
--
-- @since 0.5.5
takeWhile :: Manifest r e => (e -> Bool) -> Vector r e -> Vector r e
takeWhile :: forall r e. Manifest r e => (e -> Bool) -> Vector r e -> Vector r e
takeWhile e -> Bool
f Vector r e
v = forall r e. Source r e => Sz1 -> Vector r e -> Vector r e
take (Int -> Sz1
go Int
0) Vector r e
v
  where
    !k :: Int
k = forall ix r e. (Index ix, Size r) => Array r ix e -> Int
elemsCount Vector r e
v
    go :: Int -> Sz1
go !Int
i
      | Int
i forall a. Ord a => a -> a -> Bool
< Int
k Bool -> Bool -> Bool
&& e -> Bool
f (forall r e ix. (Source r e, Index ix) => Array r ix e -> Int -> e
unsafeLinearIndex Vector r e
v Int
i) = Int -> Sz1
go (Int
i forall a. Num a => a -> a -> a
+ Int
1)
      | Bool
otherwise = forall ix. ix -> Sz ix
SafeSz Int
i
{-# INLINE takeWhile #-}

-- | /O(1)/ - Get the vector with the first @n@ elements. Throws an error size is less
-- than @n@.
--
-- ==== __Examples__
--
-- >>> take' 0 (0 ..: 0)
-- Array D Seq (Sz1 0)
--   [  ]
-- >>> take' 5 (0 ..: 10)
-- Array D Seq (Sz1 5)
--   [ 0, 1, 2, 3, 4 ]
--
-- @since 0.5.0
take' :: forall r e. (HasCallStack, Source r e) => Sz1 -> Vector r e -> Vector r e
take' :: forall r e.
(HasCallStack, Source r e) =>
Sz1 -> Vector r e -> Vector r e
take' Sz1
k = forall a. HasCallStack => Either SomeException a -> a
throwEither forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r e (m :: * -> *).
(Source r e, MonadThrow m) =>
Sz1 -> Vector r e -> m (Vector r e)
takeM Sz1
k
{-# INLINE take' #-}

-- | /O(1)/ - Get the vector with the first @n@ elements. Throws an error size is less than @n@
--
-- ==== __Examples__
--
-- >>> import Data.Massiv.Array as A
-- >>> takeM 5 (0 ..: 10)
-- Array D Seq (Sz1 5)
--   [ 0, 1, 2, 3, 4 ]
-- >>> maybe 0 A.sum $ takeM 5 (0 ..: 10)
-- 10
-- >>> maybe (-1) A.sum $ takeM 15 (0 ..: 10)
-- -1
-- >>> takeM 15 (0 ..: 10)
-- *** Exception: SizeSubregionException: (Sz1 10) is to small for 0 (Sz1 15)
--
-- @since 0.5.0
takeM :: forall r e m. (Source r e, MonadThrow m) => Sz1 -> Vector r e -> m (Vector r e)
takeM :: forall r e (m :: * -> *).
(Source r e, MonadThrow m) =>
Sz1 -> Vector r e -> m (Vector r e)
takeM Sz1
k Vector r e
v = do
  let sz :: Sz1
sz = forall r ix e. Size r => Array r ix e -> Sz ix
size Vector r e
v
  forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Sz1
k forall a. Ord a => a -> a -> Bool
> Sz1
sz) forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwM forall a b. (a -> b) -> a -> b
$ forall ix. Index ix => Sz ix -> ix -> Sz ix -> SizeException
SizeSubregionException Sz1
sz Int
0 Sz1
k
  forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ forall r e. Source r e => Sz1 -> Vector r e -> Vector r e
unsafeTake Sz1
k Vector r e
v
{-# INLINE takeM #-}

-- | /O(1)/ - Create a `Stream` vector with the first @n@ elements. Never fails
--
-- ==== __Examples__
--
-- @since 0.5.0
stake :: forall r e. Stream r Ix1 e => Sz1 -> Vector r e -> Vector DS e
stake :: forall r e. Stream r Int e => Sz1 -> Vector r e -> Vector DS e
stake Sz1
n = forall e. Steps Id e -> Vector DS e
fromSteps forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. Monad m => Sz1 -> Steps m a -> Steps m a
S.take Sz1
n forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream
{-# INLINE stake #-}

-- | /O(1)/ - Drop @n@ elements from a vector. This function never fails and has
-- similar semantics as the `Data.List.drop` for lists.
--
-- ==== __Examples__
--
-- >>> import Data.Massiv.Array as A
-- >>> v = makeVectorR D Seq 10 id
-- >>> v
-- Array D Seq (Sz1 10)
--   [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
-- >>> A.drop 5 v
-- Array D Seq (Sz1 5)
--   [ 5, 6, 7, 8, 9 ]
-- >>> A.drop 25 v
-- Array D Seq (Sz1 0)
--   [  ]
--
-- @since 0.5.0
drop :: forall r e. Source r e => Sz1 -> Vector r e -> Vector r e
drop :: forall r e. Source r e => Sz1 -> Vector r e -> Vector r e
drop Sz1
k = forall a b. (a, b) -> b
snd forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r e.
Source r e =>
Sz1 -> Vector r e -> (Vector r e, Vector r e)
sliceAt Sz1
k
{-# INLINE drop #-}

-- | Slice a manifest vector in such a way that it will not contain all initial elements
-- that satisfy the supplied predicate.
--
-- @since 0.5.5
dropWhile :: forall r e. Manifest r e => (e -> Bool) -> Vector r e -> Vector r e
dropWhile :: forall r e. Manifest r e => (e -> Bool) -> Vector r e -> Vector r e
dropWhile e -> Bool
f Vector r e
v = forall r e. Source r e => Sz1 -> Vector r e -> Vector r e
drop (Int -> Sz1
go Int
0) Vector r e
v
  where
    !k :: Int
k = forall ix r e. (Index ix, Size r) => Array r ix e -> Int
elemsCount Vector r e
v
    go :: Int -> Sz1
go !Int
i
      | Int
i forall a. Ord a => a -> a -> Bool
< Int
k Bool -> Bool -> Bool
&& e -> Bool
f (forall r e ix. (Source r e, Index ix) => Array r ix e -> Int -> e
unsafeLinearIndex Vector r e
v Int
i) = Int -> Sz1
go (Int
i forall a. Num a => a -> a -> a
+ Int
1)
      | Bool
otherwise = forall ix. ix -> Sz ix
SafeSz Int
i
{-# INLINE dropWhile #-}

-- | Keep all but the first @n@ elements from the delayed stream vector.
--
-- ==== __Examples__
--
-- @since 0.5.0
sdrop :: forall r e. Stream r Ix1 e => Sz1 -> Vector r e -> Vector DS e
sdrop :: forall r e. Stream r Int e => Sz1 -> Vector r e -> Vector DS e
sdrop Sz1
n = forall e. Steps Id e -> Vector DS e
fromSteps forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. Monad m => Sz1 -> Steps m a -> Steps m a
S.drop Sz1
n forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream
{-# INLINE sdrop #-}

-- | /O(1)/ - Drop @n@ elements from a vector. Unlike `drop`, this function will
-- produce an error when supplied number of elements to drop is larger than size
-- of the supplied vector
--
-- ==== __Examples__
--
-- @since 0.5.0
drop' :: forall r e. (HasCallStack, Source r e) => Sz1 -> Vector r e -> Vector r e
drop' :: forall r e.
(HasCallStack, Source r e) =>
Sz1 -> Vector r e -> Vector r e
drop' Sz1
k = forall a. HasCallStack => Either SomeException a -> a
throwEither forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r e (m :: * -> *).
(Source r e, MonadThrow m) =>
Sz1 -> Vector r e -> m (Vector r e)
dropM Sz1
k
{-# INLINE drop' #-}

-- |
--
-- ==== __Examples__
--
-- @since 0.5.0
dropM :: forall r e m. (Source r e, MonadThrow m) => Sz1 -> Vector r e -> m (Vector r e)
dropM :: forall r e (m :: * -> *).
(Source r e, MonadThrow m) =>
Sz1 -> Vector r e -> m (Vector r e)
dropM k :: Sz1
k@(Sz Int
d) Vector r e
v = do
  let sz :: Sz1
sz@(Sz Int
n) = forall r ix e. Size r => Array r ix e -> Sz ix
size Vector r e
v
  forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Sz1
k forall a. Ord a => a -> a -> Bool
> Sz1
sz) forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwM forall a b. (a -> b) -> a -> b
$ forall ix. Index ix => Sz ix -> ix -> Sz ix -> SizeException
SizeSubregionException Sz1
sz Int
d (forall ix. ix -> Sz ix
SafeSz (Int
n forall a. Num a => a -> a -> a
- Int
d))
  forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ forall r e ix.
(Source r e, Index ix) =>
Int -> Sz1 -> Array r ix e -> Array r Int e
unsafeLinearSlice Int
d (forall ix. ix -> Sz ix
SafeSz (Int
n forall a. Num a => a -> a -> a
- Int
d)) Vector r e
v
{-# INLINE dropM #-}

-- | Same as 'sliceAt'', except it never fails.
--
-- ==== __Examples__
--
-- @since 0.5.0
sliceAt :: forall r e. Source r e => Sz1 -> Vector r e -> (Vector r e, Vector r e)
sliceAt :: forall r e.
Source r e =>
Sz1 -> Vector r e -> (Vector r e, Vector r e)
sliceAt (Sz Int
k) Vector r e
v = (forall r e. Source r e => Sz1 -> Vector r e -> Vector r e
unsafeTake Sz1
d Vector r e
v, forall r e. Source r e => Sz1 -> Vector r e -> Vector r e
unsafeDrop Sz1
d Vector r e
v)
  where
    !n :: Int
n = coerce :: forall a b. Coercible a b => a -> b
coerce (forall r ix e. Size r => Array r ix e -> Sz ix
size Vector r e
v)
    !d :: Sz1
d = forall ix. ix -> Sz ix
SafeSz (forall a. Ord a => a -> a -> a
min Int
k Int
n)
{-# INLINE sliceAt #-}

-- | Same as 'Data.Massiv.Array.splitAt'', except for a flat vector.
--
-- ==== __Examples__
--
-- @since 0.5.0
sliceAt' :: (HasCallStack, Source r e) => Sz1 -> Vector r e -> (Vector r e, Vector r e)
sliceAt' :: forall r e.
(HasCallStack, Source r e) =>
Sz1 -> Vector r e -> (Vector r e, Vector r e)
sliceAt' Sz1
k = forall a. HasCallStack => Either SomeException a -> a
throwEither forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r e (m :: * -> *).
(Source r e, MonadThrow m) =>
Sz1 -> Vector r e -> m (Vector r e, Vector r e)
sliceAtM Sz1
k
{-# INLINE sliceAt' #-}

-- | Same as `Data.Massiv.Array.splitAtM`, except for a flat vector.
--
-- ==== __Examples__
--
-- @since 0.5.0
sliceAtM :: forall r e m. (Source r e, MonadThrow m) => Sz1 -> Vector r e -> m (Vector r e, Vector r e)
sliceAtM :: forall r e (m :: * -> *).
(Source r e, MonadThrow m) =>
Sz1 -> Vector r e -> m (Vector r e, Vector r e)
sliceAtM Sz1
k Vector r e
v = do
  Vector r e
l <- forall r e (m :: * -> *).
(Source r e, MonadThrow m) =>
Sz1 -> Vector r e -> m (Vector r e)
takeM Sz1
k Vector r e
v
  forall (f :: * -> *) a. Applicative f => a -> f a
pure (Vector r e
l, forall r e. Source r e => Sz1 -> Vector r e -> Vector r e
unsafeDrop Sz1
k Vector r e
v)
{-# INLINE sliceAtM #-}

-- | Create an empty delayed stream vector
--
-- ==== __Examples__
--
-- @since 0.5.0
sempty :: Vector DS e
sempty :: forall e. Vector DS e
sempty = forall e. Steps Id e -> Vector DS e
DSArray forall (m :: * -> *) e. Monad m => Steps m e
S.empty
{-# INLINE sempty #-}

-- | Create a delayed stream vector with a single element
--
-- ==== __Examples__
--
-- @since 0.5.0
ssingleton :: e -> Vector DS e
ssingleton :: forall e. e -> Vector DS e
ssingleton = forall e. Steps Id e -> Vector DS e
DSArray forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) e. Monad m => e -> Steps m e
S.singleton
{-# INLINE ssingleton #-}

-- | /O(1)/ - Add an element to the vector from the left side
--
-- @since 0.3.0
cons :: forall r e. (Size r, Load r Ix1 e) => e -> Vector r e -> Vector DL e
cons :: forall r e.
(Size r, Load r Int e) =>
e -> Vector r e -> Vector DL e
cons e
e Vector r e
v =
  let dv :: Array DL Int e
dv = forall r ix e.
(Size r, Load r ix e) =>
Array r ix e -> Array DL ix e
toLoadArray Vector r e
v
      load :: Scheduler s ()
-> Int
-> (Int -> e -> ST s ())
-> (Int -> Sz1 -> e -> ST s ())
-> ST s ()
load Scheduler s ()
scheduler Int
startAt Int -> e -> ST s ()
uWrite Int -> Sz1 -> e -> ST s ()
uSet =
        Int -> e -> ST s ()
uWrite Int
startAt e
e forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall ix e. Array DL ix e -> Loader e
dlLoad Array DL Int e
dv Scheduler s ()
scheduler (Int
startAt forall a. Num a => a -> a -> a
+ Int
1) Int -> e -> ST s ()
uWrite Int -> Sz1 -> e -> ST s ()
uSet
      {-# INLINE load #-}
   in Array DL Int e
dv{dlSize :: Sz1
dlSize = forall ix. ix -> Sz ix
SafeSz (Int
1 forall a. Num a => a -> a -> a
+ forall ix. Sz ix -> ix
unSz (forall ix e. Array DL ix e -> Sz ix
dlSize Array DL Int e
dv)), dlLoad :: Loader e
dlLoad = Loader e
load}
{-# INLINE cons #-}

-- | /O(1)/ - Add an element to the vector from the right side
--
-- @since 0.3.0
snoc :: forall r e. (Size r, Load r Ix1 e) => Vector r e -> e -> Vector DL e
snoc :: forall r e.
(Size r, Load r Int e) =>
Vector r e -> e -> Vector DL e
snoc Vector r e
v e
e =
  let dv :: Array DL Int e
dv = forall r ix e.
(Size r, Load r ix e) =>
Array r ix e -> Array DL ix e
toLoadArray Vector r e
v
      !k :: Int
k = forall ix. Sz ix -> ix
unSz (forall r ix e. Size r => Array r ix e -> Sz ix
size Array DL Int e
dv)
      load :: Scheduler s ()
-> Int
-> (Int -> e -> ST s ())
-> (Int -> Sz1 -> e -> ST s ())
-> ST s ()
load Scheduler s ()
scheduler Int
startAt Int -> e -> ST s ()
uWrite Int -> Sz1 -> e -> ST s ()
uSet =
        forall ix e. Array DL ix e -> Loader e
dlLoad Array DL Int e
dv Scheduler s ()
scheduler Int
startAt Int -> e -> ST s ()
uWrite Int -> Sz1 -> e -> ST s ()
uSet forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Int -> e -> ST s ()
uWrite (Int
k forall a. Num a => a -> a -> a
+ Int
startAt) e
e
      {-# INLINE load #-}
   in Array DL Int e
dv{dlSize :: Sz1
dlSize = forall ix. ix -> Sz ix
SafeSz (Int
1 forall a. Num a => a -> a -> a
+ Int
k), dlLoad :: Loader e
dlLoad = Loader e
load}
{-# INLINE snoc #-}

-- | Replicate the same element @n@ times
--
-- ==== __Examples__
--
-- @since 0.5.0
sreplicate :: Sz1 -> e -> Vector DS e
sreplicate :: forall e. Sz1 -> e -> Vector DS e
sreplicate Sz1
n = forall e. Steps Id e -> Vector DS e
DSArray forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. Monad m => Sz1 -> a -> Steps m a
S.replicate Sz1
n
{-# INLINE sreplicate #-}

-- | Create a delayed vector of length @n@ with a function that maps an index to an
-- element. Same as `makeLinearArray`
--
-- ==== __Examples__
--
-- @since 0.5.0
generate :: Comp -> Sz1 -> (Ix1 -> e) -> Vector D e
generate :: forall e. Comp -> Sz1 -> (Int -> e) -> Vector D e
generate = forall r ix e.
Load r ix e =>
Comp -> Sz ix -> (Int -> e) -> Array r ix e
makeArrayLinear
{-# INLINE generate #-}

-- | Create a delayed stream vector of length @n@ with a function that maps an index to an
-- element. Same as `makeLinearArray`
--
-- ==== __Examples__
--
-- @since 0.5.0
sgenerate :: Sz1 -> (Ix1 -> e) -> Vector DS e
sgenerate :: forall e. Sz1 -> (Int -> e) -> Vector DS e
sgenerate Sz1
n = forall e. Steps Id e -> Vector DS e
DSArray forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) e. Monad m => Sz1 -> (Int -> e) -> Steps m e
S.generate Sz1
n
{-# INLINE sgenerate #-}

-- | Create a delayed stream vector of infinite length by repeatedly applying a function to the
-- initial value.
--
-- ==== __Examples__
--
-- >>> stake 10 $ siterate succ 'a'
-- Array DS Seq (Sz1 10)
--   [ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j' ]
--
-- @since 0.5.2
siterate :: (e -> e) -> e -> Vector DS e
siterate :: forall e. (e -> e) -> e -> Vector DS e
siterate e -> e
f = forall e. Steps Id e -> Vector DS e
fromSteps forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) s e.
Monad m =>
(s -> Maybe (e, s)) -> s -> Steps m e
S.unfoldr (\e
a -> forall a. a -> Maybe a
Just (e
a, e -> e
f e
a))
{-# INLINE siterate #-}

-- | Create a delayed stream vector of length @n@ by repeatedly applying a function to the
-- initial value.
--
-- ==== __Examples__
--
-- >>> siterateN 10 succ 'a'
-- Array DS Seq (Sz1 10)
--   [ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j' ]
--
-- @since 0.5.0
siterateN :: Sz1 -> (e -> e) -> e -> Vector DS e
siterateN :: forall e. Sz1 -> (e -> e) -> e -> Vector DS e
siterateN Sz1
n e -> e
f e
a = forall e. Steps Id e -> Vector DS e
fromSteps forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a.
Monad m =>
Sz1 -> (a -> a) -> a -> Steps m a
S.iterateN Sz1
n e -> e
f e
a
{-# INLINE siterateN #-}

-- | Create a vector by using the same monadic action @n@ times
--
-- ==== __Examples__
--
-- @since 0.5.0
sreplicateM :: forall e m. Monad m => Sz1 -> m e -> m (Vector DS e)
sreplicateM :: forall e (m :: * -> *). Monad m => Sz1 -> m e -> m (Vector DS e)
sreplicateM Sz1
n m e
f = forall (m :: * -> *) e. Monad m => Steps m e -> m (Vector DS e)
fromStepsM forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. Monad m => Sz1 -> m a -> Steps m a
S.replicateM Sz1
n m e
f
{-# INLINE sreplicateM #-}

-- | Create a delayed stream vector of length @n@ with a monadic action that from an index
-- generates an element.
--
-- ==== __Examples__
--
-- @since 0.5.0
sgenerateM :: forall e m. Monad m => Sz1 -> (Ix1 -> m e) -> m (Vector DS e)
sgenerateM :: forall e (m :: * -> *).
Monad m =>
Sz1 -> (Int -> m e) -> m (Vector DS e)
sgenerateM Sz1
n Int -> m e
f = forall (m :: * -> *) e. Monad m => Steps m e -> m (Vector DS e)
fromStepsM forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. Monad m => Sz1 -> (Int -> m a) -> Steps m a
S.generateM Sz1
n Int -> m e
f
{-# INLINE sgenerateM #-}

-- | Create a delayed stream vector of length @n@ by repeatedly apply a monadic action to
-- the initial value.
--
-- ==== __Examples__
--
-- @since 0.5.0
siterateNM :: forall e m. Monad m => Sz1 -> (e -> m e) -> e -> m (Vector DS e)
siterateNM :: forall e (m :: * -> *).
Monad m =>
Sz1 -> (e -> m e) -> e -> m (Vector DS e)
siterateNM Sz1
n e -> m e
f e
a = forall (m :: * -> *) e. Monad m => Steps m e -> m (Vector DS e)
fromStepsM forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a.
Monad m =>
Sz1 -> (a -> m a) -> a -> Steps m a
S.iterateNM Sz1
n e -> m e
f e
a
{-# INLINE siterateNM #-}

-- | Right unfolding function. Useful when it is unknown ahead of time how many
-- elements a vector will have.
--
-- ====__Example__
--
-- >>> import Data.Massiv.Array as A
-- >>> sunfoldr (\i -> if i < 9 then Just (i * i, i + 1) else Nothing) (0 :: Int)
-- Array DS Seq (Sz1 9)
--   [ 0, 1, 4, 9, 16, 25, 36, 49, 64 ]
--
-- @since 0.5.0
sunfoldr :: forall e s. (s -> Maybe (e, s)) -> s -> Vector DS e
sunfoldr :: forall e s. (s -> Maybe (e, s)) -> s -> Vector DS e
sunfoldr s -> Maybe (e, s)
f = forall e. Steps Id e -> Vector DS e
DSArray forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) s e.
Monad m =>
(s -> Maybe (e, s)) -> s -> Steps m e
S.unfoldr s -> Maybe (e, s)
f
{-# INLINE sunfoldr #-}

-- | /O(n)/ - Right unfolding function with at most @n@ number of elements.
--
-- ==== __Example__
--
-- >>> import Data.Massiv.Array as A
-- >>> sunfoldrN 9 (\i -> Just (i*i, i + 1)) (0 :: Int)
-- Array DS Seq (Sz1 9)
--   [ 0, 1, 4, 9, 16, 25, 36, 49, 64 ]
--
-- @since 0.5.0
sunfoldrN
  :: forall e s
   . Sz1
  -- ^ @n@ - maximum number of elements that the vector will have
  -> (s -> Maybe (e, s))
  -- ^ Unfolding function. Stops when `Nothing` is returned or maximum number of elements
  -- is reached.
  -> s
  -- ^ Inititial element.
  -> Vector DS e
sunfoldrN :: forall e s. Sz1 -> (s -> Maybe (e, s)) -> s -> Vector DS e
sunfoldrN Sz1
n s -> Maybe (e, s)
f = forall e. Steps Id e -> Vector DS e
DSArray forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) s e.
Monad m =>
Sz1 -> (s -> Maybe (e, s)) -> s -> Steps m e
S.unfoldrN Sz1
n s -> Maybe (e, s)
f
{-# INLINE sunfoldrN #-}

-- | /O(n)/ - Same as `sunfoldr`, but with monadic generating function.
--
-- ==== __Examples__
--
-- >>> import Control.Monad (when, guard)
-- >>> sunfoldrM (\i -> when (i == 0) (Left "Zero denominator") >> Right (guard (i < 5) >> Just (100 `div` i, i + 1))) (-10 :: Int)
-- Left "Zero denominator"
-- >>> sunfoldrM (\i -> when (i == 0) (Left "Zero denominator") >> Right (guard (i < -5) >> Just (100 `div` i, i + 1))) (-10 :: Int)
-- Right (Array DS Seq (Sz1 5)
--   [ -10, -12, -13, -15, -17 ]
-- )
--
-- @since 0.5.0
sunfoldrM :: forall e s m. Monad m => (s -> m (Maybe (e, s))) -> s -> m (Vector DS e)
sunfoldrM :: forall e s (m :: * -> *).
Monad m =>
(s -> m (Maybe (e, s))) -> s -> m (Vector DS e)
sunfoldrM s -> m (Maybe (e, s))
f = forall (m :: * -> *) e. Monad m => Steps m e -> m (Vector DS e)
fromStepsM forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) s e.
Monad m =>
(s -> m (Maybe (e, s))) -> s -> Steps m e
S.unfoldrM s -> m (Maybe (e, s))
f
{-# INLINE sunfoldrM #-}

-- | /O(n)/ - Same as `sunfoldrN`, but with monadic generating function.
--
-- ==== __Examples__
--
-- >>> import Control.Monad (guard)
-- >>> sunfoldrNM 6 (\i -> print i >> pure (guard (i < 5) >> Just (i * i, i + 1))) (10 :: Int)
-- 10
-- Array DS Seq (Sz1 0)
--   [  ]
-- >>> sunfoldrNM 6 (\i -> print i >> pure (guard (i < 15) >> Just (i * i, i + 1))) (10 :: Int)
-- 10
-- 11
-- 12
-- 13
-- 14
-- 15
-- Array DS Seq (Sz1 5)
--   [ 100, 121, 144, 169, 196 ]
--
--
-- @since 0.5.0
sunfoldrNM :: forall e s m. Monad m => Sz1 -> (s -> m (Maybe (e, s))) -> s -> m (Vector DS e)
sunfoldrNM :: forall e s (m :: * -> *).
Monad m =>
Sz1 -> (s -> m (Maybe (e, s))) -> s -> m (Vector DS e)
sunfoldrNM (Sz Int
n) s -> m (Maybe (e, s))
f = forall (m :: * -> *) e. Monad m => Steps m e -> m (Vector DS e)
fromStepsM forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) s e.
Monad m =>
Int -> (s -> m (Maybe (e, s))) -> s -> Steps m e
S.unfoldrNM Int
n s -> m (Maybe (e, s))
f
{-# INLINE sunfoldrNM #-}

-- | /O(n)/ - Similar to `sunfoldrN`, except the length of the resulting vector will be exactly @n@
--
-- ==== __Examples__
--
-- >>> sunfoldrExactN 10 (\i -> (i * i, i + 1)) (10 :: Int)
-- Array DS Seq (Sz1 10)
--   [ 100, 121, 144, 169, 196, 225, 256, 289, 324, 361 ]
--
-- @since 0.5.0
sunfoldrExactN :: forall e s. Sz1 -> (s -> (e, s)) -> s -> Vector DS e
sunfoldrExactN :: forall e s. Sz1 -> (s -> (e, s)) -> s -> Vector DS e
sunfoldrExactN Sz1
n s -> (e, s)
f = forall e. Steps Id e -> Vector DS e
fromSteps forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) s a.
Monad m =>
Sz1 -> (s -> (a, s)) -> s -> Steps m a
S.unfoldrExactN Sz1
n s -> (e, s)
f
{-# INLINE sunfoldrExactN #-}

-- | /O(n)/ - Similar to `sunfoldrNM`, except the length of the resulting vector will be exactly @n@
--
-- ==== __Examples__
--
-- λ> sunfoldrExactNM 11 (\i -> pure (100 `div` i, i + 1)) (-10 :: Int)
-- Array DS *** Exception: divide by zero
-- λ> sunfoldrExactNM 11 (\i -> guard (i /= 0) >> Just (100 `div` i, i + 1)) (-10 :: Int)
-- Nothing
-- λ> sunfoldrExactNM 9 (\i -> guard (i /= 0) >> Just (100 `div` i, i + 1)) (-10 :: Int)
-- Just (Array DS Seq (Sz1 9)
--   [ -10, -12, -13, -15, -17, -20, -25, -34, -50 ]
-- )
--
-- @since 0.5.0
sunfoldrExactNM :: forall e s m. Monad m => Sz1 -> (s -> m (e, s)) -> s -> m (Vector DS e)
sunfoldrExactNM :: forall e s (m :: * -> *).
Monad m =>
Sz1 -> (s -> m (e, s)) -> s -> m (Vector DS e)
sunfoldrExactNM Sz1
n s -> m (e, s)
f = forall (m :: * -> *) e. Monad m => Steps m e -> m (Vector DS e)
fromStepsM forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) s a.
Monad m =>
Sz1 -> (s -> m (a, s)) -> s -> Steps m a
S.unfoldrExactNM Sz1
n s -> m (e, s)
f
{-# INLINE sunfoldrExactNM #-}

-- | /O(n)/ - Enumerate from a starting number @x@ exactly @n@ times with a step @1@.
--
-- /Related/: `senumFromStepN`, `enumFromN`, `enumFromStepN`, `rangeSize`,
-- `rangeStepSize`, `range`, 'rangeStep''
--
-- ==== __Examples__
--
-- >>> senumFromN (10 :: Int) 9
-- Array DS Seq (Sz1 9)
--   [ 10, 11, 12, 13, 14, 15, 16, 17, 18 ]
--
-- /__Similar__/:
--
-- [@Prelude.`Prelude.enumFromTo`@] Very similar to @[x .. x + n - 1]@, except that
-- `senumFromN` is faster and it only works for `Num` and not for `Enum` elements
--
-- [@Data.Vector.Generic.`Data.Vector.Generic.enumFromN`@] Uses exactly the same
-- implementation underneath.
--
-- @since 0.5.0
senumFromN
  :: Num e
  => e
  -- ^ @x@ - starting number
  -> Sz1
  -- ^ @n@ - length of resulting vector
  -> Vector DS e
senumFromN :: forall e. Num e => e -> Sz1 -> Vector DS e
senumFromN e
x Sz1
n = forall e. Steps Id e -> Vector DS e
DSArray forall a b. (a -> b) -> a -> b
$ forall a (m :: * -> *).
(Num a, Monad m) =>
a -> a -> Sz1 -> Steps m a
S.enumFromStepN e
x e
1 Sz1
n
{-# INLINE senumFromN #-}

-- | /O(n)/ - Enumerate from a starting number @x@ exactly @n@ times with a custom step value @dx@
--
-- ==== __Examples__
--
-- >>> senumFromStepN (5 :: Int) 2 10
-- Array DS Seq (Sz1 10)
--   [ 5, 7, 9, 11, 13, 15, 17, 19, 21, 23 ]
--
-- __/Similar/__:
--
-- [@Prelude.`Prelude.enumFrom`@] Just like @take n [x, x + dx ..]@, except that
-- `senumFromN` is faster and it only works for `Num` and not for `Enum` elements
--
-- [@Data.Vector.Generic.`Data.Vector.Generic.enumFromStepN`@] Uses exactly the same
-- implementation underneath.
--
-- @since 0.5.0
senumFromStepN
  :: Num e
  => e
  -- ^ @x@ - starting number
  -> e
  -- ^ @dx@ - Step
  -> Sz1
  -- ^ @n@ - length of resulting vector
  -> Vector DS e
senumFromStepN :: forall e. Num e => e -> e -> Sz1 -> Vector DS e
senumFromStepN e
x e
step Sz1
n = forall e. Steps Id e -> Vector DS e
DSArray forall a b. (a -> b) -> a -> b
$ forall a (m :: * -> *).
(Num a, Monad m) =>
a -> a -> Sz1 -> Steps m a
S.enumFromStepN e
x e
step Sz1
n
{-# INLINE senumFromStepN #-}

-- | Append two vectors together
--
-- /Related/: `appendM`, `appendOuterM`,
--
-- ==== __Examples__
--
-- λ> sappend (1 ..: 6) (senumFromStepN 6 (-1) 6)
-- Array DS Seq (Sz1 11)
--   [ 1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1 ]
--
-- __/Similar/__:
--
-- [@Data.Semigroup.`Data.Semigroup.<>`@] `DS` and `DL` arrays have instances for
-- `Semigroup`, so they will work in a similar fashion. `sappend` differs in that it accepts
-- `Stream` arrays with possibly different representations.
--
-- [@Data.List.`Data.List.++`@] Same operation, but for lists.
--
-- [@Data.Vector.Generic.`Data.Vector.Generic.++`@] Uses exactly the same implementation
-- underneath as `sappend`, except that it cannot append two vectors with different
-- memory representations.
--
-- @since 0.5.0
sappend
  :: forall r1 r2 e
   . (Stream r1 Ix1 e, Stream r2 Ix1 e)
  => Vector r1 e
  -> Vector r2 e
  -> Vector DS e
sappend :: forall r1 r2 e.
(Stream r1 Int e, Stream r2 Int e) =>
Vector r1 e -> Vector r2 e -> Vector DS e
sappend Vector r1 e
a1 Vector r2 e
a2 = forall e. Steps Id e -> Vector DS e
fromSteps (forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
toStream Vector r1 e
a1 forall (m :: * -> *) e.
Monad m =>
Steps m e -> Steps m e -> Steps m e
`S.append` forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
toStream Vector r2 e
a2)
{-# INLINE sappend #-}

-- | Concat vectors together
--
-- /Related/: `concatM`, `concatOuterM`,
--
-- ==== __Examples__
--
-- >>> sconcat [2 ... 6, empty, singleton 1, generate Seq 5 id]
-- Array DS Seq (Sz1 11)
--   [ 2, 3, 4, 5, 6, 1, 0, 1, 2, 3, 4 ]
-- >>> sconcat [senumFromN 2 5, sempty, ssingleton 1, sgenerate 5 id]
-- Array DS Seq (Sz1 11)
--   [ 2, 3, 4, 5, 6, 1, 0, 1, 2, 3, 4 ]
--
-- __/Similar/__:
--
-- [@Data.Monoid.`Data.Monoid.mconcat`@] `DS` and `DL` arrays have instances for `Monoid`, so
-- they will work in a similar fashion. `sconcat` differs in that it accepts `Stream`
-- arrays of other representations.
--
-- [@Data.List.`Data.List.concat`@] Same operation, but for lists.
--
-- [@Data.Vector.Generic.`Data.Vector.Generic.concat`@] Uses exactly the same
-- implementation underneath as `sconcat`.
--
-- @since 0.5.0
sconcat :: forall r e. Stream r Ix1 e => [Vector r e] -> Vector DS e
sconcat :: forall r e. Stream r Int e => [Vector r e] -> Vector DS e
sconcat = forall e. Steps Id e -> Vector DS e
DSArray forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
toStream
{-# INLINE sconcat #-}

-- | Convert a list to a delayed stream vector
--
-- /Related/: `fromList`, `fromListN`, `sfromListN`
--
-- ==== __Examples__
--
-- >>> sfromList ([] :: [Int])
-- Array DS Seq (Sz1 0)
--   [  ]
-- >>> sfromList ([1,2,3] :: [Int])
-- Array DS Seq (Sz1 3)
--   [ 1, 2, 3 ]
--
-- @since 0.5.0
sfromList :: [e] -> Vector DS e
sfromList :: forall e. [e] -> Vector DS e
sfromList = forall e. Steps Id e -> Vector DS e
fromSteps forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) e. Monad m => [e] -> Steps m e
S.fromList
{-# INLINE sfromList #-}

-- | Convert a list to a delayed stream vector. Length of the resulting vector will be at
-- most @n@. This version isn't really more efficient then `sfromList`, but there is
-- `Data.Massiv.Array.Unsafe.unsafeFromListN`
--
-- /Related/: `fromList`, `fromListN`, `sfromList`
--
-- ==== __Examples__
--
-- >>> sfromListN 10 [1 :: Int ..]
-- Array DS Seq (Sz1 10)
--   [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
-- >>> sfromListN 10 [1 :: Int .. 5]
-- Array DS Seq (Sz1 5)
--   [ 1, 2, 3, 4, 5 ]
--
-- @since 0.5.1
sfromListN :: Sz1 -> [e] -> Vector DS e
sfromListN :: forall e. Sz1 -> [e] -> Vector DS e
sfromListN (Sz Int
n) = forall e. Steps Id e -> Vector DS e
fromSteps forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) e. Monad m => Int -> [e] -> Steps m e
S.fromListN Int
n
{-# INLINE sfromListN #-}

-- | Convert an array to a list by the means of a delayed stream vector.
--
-- /Related/: `toList`
--
-- ==== __Examples__
--
-- @since 0.5.0
stoList :: forall r ix e. Stream r ix e => Array r ix e -> [e]
stoList :: forall r ix e. Stream r ix e => Array r ix e -> [e]
stoList = forall e. Steps Id e -> [e]
S.toList forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
toStream
{-# INLINE stoList #-}

-- | Sequentially filter out elements from the array according to the supplied predicate.
--
-- ==== __Example__
--
-- >>> import Data.Massiv.Array as A
-- >>> arr = makeArrayR D Seq (Sz2 3 4) fromIx2
-- >>> arr
-- Array D Seq (Sz (3 :. 4))
--   [ [ (0,0), (0,1), (0,2), (0,3) ]
--   , [ (1,0), (1,1), (1,2), (1,3) ]
--   , [ (2,0), (2,1), (2,2), (2,3) ]
--   ]
-- >>> sfilter (even . fst) arr
-- Array DS Seq (Sz1 8)
--   [ (0,0), (0,1), (0,2), (0,3), (2,0), (2,1), (2,2), (2,3) ]
--
-- @since 0.5.0
sfilter :: forall r ix e. S.Stream r ix e => (e -> Bool) -> Array r ix e -> Vector DS e
sfilter :: forall r ix e.
Stream r ix e =>
(e -> Bool) -> Array r ix e -> Vector DS e
sfilter e -> Bool
f = forall e. Steps Id e -> Vector DS e
DSArray forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a.
Monad m =>
(a -> Bool) -> Steps m a -> Steps m a
S.filter e -> Bool
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream
{-# INLINE sfilter #-}

-- | Similar to `sfilter`, but filter with an index aware function.
--
-- ==== __Examples__
--
-- @since 0.5.0
sifilter :: forall r ix e. Stream r ix e => (ix -> e -> Bool) -> Array r ix e -> Vector DS e
sifilter :: forall r ix e.
Stream r ix e =>
(ix -> e -> Bool) -> Array r ix e -> Vector DS e
sifilter ix -> e -> Bool
f =
  forall r ix a b.
Stream r ix a =>
(ix -> a -> Maybe b) -> Array r ix a -> Vector DS b
simapMaybe forall a b. (a -> b) -> a -> b
$ \ix
ix e
e ->
    if ix -> e -> Bool
f ix
ix e
e
      then forall a. a -> Maybe a
Just e
e
      else forall a. Maybe a
Nothing
{-# INLINE sifilter #-}

-- | Sequentially filter out elements from the array according to the supplied applicative predicate.
--
-- ==== __Example__
--
-- >>> import Data.Massiv.Array as A
-- >>> arr = makeArrayR D Seq (Sz2 3 4) fromIx2
-- >>> arr
-- Array D Seq (Sz (3 :. 4))
--   [ [ (0,0), (0,1), (0,2), (0,3) ]
--   , [ (1,0), (1,1), (1,2), (1,3) ]
--   , [ (2,0), (2,1), (2,2), (2,3) ]
--   ]
-- >>> sfilterM (Just . odd . fst) arr
-- Just (Array DS Seq (Sz1 4)
--   [ (1,0), (1,1), (1,2), (1,3) ]
-- )
-- >>> sfilterM (\ix@(_, j) -> print ix >> return (even j)) arr
-- (0,0)
-- (0,1)
-- (0,2)
-- (0,3)
-- (1,0)
-- (1,1)
-- (1,2)
-- (1,3)
-- (2,0)
-- (2,1)
-- (2,2)
-- (2,3)
-- Array DS Seq (Sz1 6)
--   [ (0,0), (0,2), (1,0), (1,2), (2,0), (2,2) ]
--
-- @since 0.5.0
sfilterM
  :: forall r ix e f
   . (S.Stream r ix e, Applicative f)
  => (e -> f Bool)
  -> Array r ix e
  -> f (Vector DS e)
sfilterM :: forall r ix e (f :: * -> *).
(Stream r ix e, Applicative f) =>
(e -> f Bool) -> Array r ix e -> f (Vector DS e)
sfilterM e -> f Bool
f Array r ix e
arr = forall e. Steps Id e -> Vector DS e
DSArray forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) (f :: * -> *) e.
(Monad m, Applicative f) =>
(e -> f Bool) -> Steps Id e -> f (Steps m e)
S.filterA e -> f Bool
f (forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream Array r ix e
arr)
{-# INLINE sfilterM #-}

-- | Similar to `filterM`, but filter with an index aware function.
--
-- Corresponds to: @`filterM` (uncurry f) . `simap` (,)@
--
-- @since 0.5.0
sifilterM
  :: forall r ix e f
   . (Stream r ix e, Applicative f)
  => (ix -> e -> f Bool)
  -> Array r ix e
  -> f (Vector DS e)
sifilterM :: forall r ix e (f :: * -> *).
(Stream r ix e, Applicative f) =>
(ix -> e -> f Bool) -> Array r ix e -> f (Vector DS e)
sifilterM ix -> e -> f Bool
f =
  forall r ix a b (f :: * -> *).
(Stream r ix a, Applicative f) =>
(ix -> a -> f (Maybe b)) -> Array r ix a -> f (Vector DS b)
simapMaybeM forall a b. (a -> b) -> a -> b
$ \ix
ix e
e ->
    ( \Bool
p ->
        if Bool
p
          then forall a. a -> Maybe a
Just e
e
          else forall a. Maybe a
Nothing
    )
      forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ix -> e -> f Bool
f ix
ix e
e
{-# INLINE sifilterM #-}

-- | Apply a function to each element of the array, while discarding `Nothing` and
-- keeping the `Maybe` result.
--
-- ==== __Examples__
--
-- @since 0.5.0
smapMaybe :: forall r ix a b. S.Stream r ix a => (a -> Maybe b) -> Array r ix a -> Vector DS b
smapMaybe :: forall r ix a b.
Stream r ix a =>
(a -> Maybe b) -> Array r ix a -> Vector DS b
smapMaybe a -> Maybe b
f = forall e. Steps Id e -> Vector DS e
DSArray forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a e.
Monad m =>
(a -> Maybe e) -> Steps m a -> Steps m e
S.mapMaybe a -> Maybe b
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream
{-# INLINE smapMaybe #-}

-- | Similar to `smapMaybe`, but map with an index aware function.
--
-- ==== __Examples__
--
-- @since 0.5.0
simapMaybe
  :: forall r ix a b
   . Stream r ix a
  => (ix -> a -> Maybe b)
  -> Array r ix a
  -> Vector DS b
simapMaybe :: forall r ix a b.
Stream r ix a =>
(ix -> a -> Maybe b) -> Array r ix a -> Vector DS b
simapMaybe ix -> a -> Maybe b
f = forall e. Steps Id e -> Vector DS e
DSArray forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a e.
Monad m =>
(a -> Maybe e) -> Steps m a -> Steps m e
S.mapMaybe (forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry ix -> a -> Maybe b
f) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r ix e. Stream r ix e => Array r ix e -> Steps Id (ix, e)
toStreamIx
{-# INLINE simapMaybe #-}

-- | Similar to `smapMaybeM`, but map with an index aware function.
--
-- ==== __Examples__
--
-- @since 0.5.0
simapMaybeM
  :: forall r ix a b f
   . (Stream r ix a, Applicative f)
  => (ix -> a -> f (Maybe b))
  -> Array r ix a
  -> f (Vector DS b)
simapMaybeM :: forall r ix a b (f :: * -> *).
(Stream r ix a, Applicative f) =>
(ix -> a -> f (Maybe b)) -> Array r ix a -> f (Vector DS b)
simapMaybeM ix -> a -> f (Maybe b)
f = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall e. Steps Id e -> Vector DS e
DSArray forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) (f :: * -> *) a e.
(Monad m, Applicative f) =>
(a -> f (Maybe e)) -> Steps Id a -> f (Steps m e)
S.mapMaybeA (forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry ix -> a -> f (Maybe b)
f) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r ix e. Stream r ix e => Array r ix e -> Steps Id (ix, e)
toStreamIx
{-# INLINE simapMaybeM #-}

-- | Keep all `Maybe`s and discard the `Nothing`s.
--
-- ==== __Examples__
--
-- @since 0.5.0
scatMaybes :: forall r ix a. S.Stream r ix (Maybe a) => Array r ix (Maybe a) -> Vector DS a
scatMaybes :: forall r ix a.
Stream r ix (Maybe a) =>
Array r ix (Maybe a) -> Vector DS a
scatMaybes = forall r ix a b.
Stream r ix a =>
(a -> Maybe b) -> Array r ix a -> Vector DS b
smapMaybe forall a. a -> a
id
{-# INLINE scatMaybes #-}

-- | Similar to `smapMaybe`, but with the `Applicative` function.
--
-- Similar to @mapMaybe id <$> mapM f arr@
--
-- ==== __Examples__
--
-- @since 0.5.0
smapMaybeM
  :: forall r ix a b f
   . (S.Stream r ix a, Applicative f)
  => (a -> f (Maybe b))
  -> Array r ix a
  -> f (Vector DS b)
smapMaybeM :: forall r ix a b (f :: * -> *).
(Stream r ix a, Applicative f) =>
(a -> f (Maybe b)) -> Array r ix a -> f (Vector DS b)
smapMaybeM a -> f (Maybe b)
f = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall e. Steps Id e -> Vector DS e
DSArray forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) (f :: * -> *) a e.
(Monad m, Applicative f) =>
(a -> f (Maybe e)) -> Steps Id a -> f (Steps m e)
S.mapMaybeA a -> f (Maybe b)
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream
{-# INLINE smapMaybeM #-}

-- | Map a function over a stream vector
--
-- ==== __Examples__
--
-- @since 0.5.0
smap
  :: forall r ix a b
   . S.Stream r ix a
  => (a -> b)
  -> Array r ix a
  -> Vector DS b
smap :: forall r ix a b.
Stream r ix a =>
(a -> b) -> Array r ix a -> Vector DS b
smap a -> b
f = forall e. Steps Id e -> Vector DS e
fromSteps forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) e a.
Monad m =>
(e -> a) -> Steps m e -> Steps m a
S.map a -> b
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream
{-# INLINE smap #-}

-- | Map an index aware function over a stream vector
--
-- ==== __Examples__
--
-- @since 0.5.0
simap
  :: forall r ix a b
   . S.Stream r ix a
  => (ix -> a -> b)
  -> Array r ix a
  -> Vector DS b
simap :: forall r ix a b.
Stream r ix a =>
(ix -> a -> b) -> Array r ix a -> Vector DS b
simap ix -> a -> b
f = forall e. Steps Id e -> Vector DS e
fromSteps forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) e a.
Monad m =>
(e -> a) -> Steps m e -> Steps m a
S.map (forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry ix -> a -> b
f) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r ix e. Stream r ix e => Array r ix e -> Steps Id (ix, e)
S.toStreamIx
{-# INLINE simap #-}

-- | Traverse a stream vector with an applicative function.
--
-- ==== __Examples__
--
-- @since 0.5.0
straverse
  :: forall r ix a b f
   . (S.Stream r ix a, Applicative f)
  => (a -> f b)
  -> Array r ix a
  -> f (Vector DS b)
straverse :: forall r ix a b (f :: * -> *).
(Stream r ix a, Applicative f) =>
(a -> f b) -> Array r ix a -> f (Vector DS b)
straverse a -> f b
f = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall e. Steps Id e -> Vector DS e
fromSteps forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) (f :: * -> *) e a.
(Monad m, Applicative f) =>
(e -> f a) -> Steps Id e -> f (Steps m a)
S.traverse a -> f b
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream
{-# INLINE straverse #-}

-- | Traverse a stream vector with an index aware applicative function.
--
-- ==== __Examples__
--
-- @since 0.5.0
sitraverse
  :: forall r ix a b f
   . (S.Stream r ix a, Applicative f)
  => (ix -> a -> f b)
  -> Array r ix a
  -> f (Vector DS b)
sitraverse :: forall r ix a b (f :: * -> *).
(Stream r ix a, Applicative f) =>
(ix -> a -> f b) -> Array r ix a -> f (Vector DS b)
sitraverse ix -> a -> f b
f = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall e. Steps Id e -> Vector DS e
fromSteps forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) (f :: * -> *) e a.
(Monad m, Applicative f) =>
(e -> f a) -> Steps Id e -> f (Steps m a)
S.traverse (forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry ix -> a -> f b
f) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r ix e. Stream r ix e => Array r ix e -> Steps Id (ix, e)
S.toStreamIx
{-# INLINE sitraverse #-}

-- | Traverse a stream vector with a monadic function.
--
-- ==== __Examples__
--
-- @since 0.5.0
smapM
  :: forall r ix a b m
   . (S.Stream r ix a, Monad m)
  => (a -> m b)
  -> Array r ix a
  -> m (Vector DS b)
smapM :: forall r ix a b (m :: * -> *).
(Stream r ix a, Monad m) =>
(a -> m b) -> Array r ix a -> m (Vector DS b)
smapM a -> m b
f = forall (m :: * -> *) e. Monad m => Steps m e -> m (Vector DS e)
fromStepsM forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) e a.
Monad m =>
(e -> m a) -> Steps m e -> Steps m a
S.mapM a -> m b
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) e. Monad m => Steps Id e -> Steps m e
S.transStepsId forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream
{-# INLINE smapM #-}

-- | Traverse a stream vector with a monadic index aware function.
--
-- Corresponds to: @mapM (uncurry f) . imap (,) v@
--
-- ==== __Examples__
--
-- @since 0.5.0
simapM
  :: forall r ix a b m
   . (S.Stream r ix a, Monad m)
  => (ix -> a -> m b)
  -> Array r ix a
  -> m (Vector DS b)
simapM :: forall r ix a b (m :: * -> *).
(Stream r ix a, Monad m) =>
(ix -> a -> m b) -> Array r ix a -> m (Vector DS b)
simapM ix -> a -> m b
f = forall (m :: * -> *) e. Monad m => Steps m e -> m (Vector DS e)
fromStepsM forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) e a.
Monad m =>
(e -> m a) -> Steps m e -> Steps m a
S.mapM (forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry ix -> a -> m b
f) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) e. Monad m => Steps Id e -> Steps m e
S.transStepsId forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r ix e. Stream r ix e => Array r ix e -> Steps Id (ix, e)
S.toStreamIx
{-# INLINE simapM #-}

-- | Traverse a stream vector with a monadic function, while discarding the result
--
-- ==== __Examples__
--
-- @since 0.5.0
smapM_
  :: forall r ix a b m
   . (S.Stream r ix a, Monad m)
  => (a -> m b)
  -> Array r ix a
  -> m ()
smapM_ :: forall r ix a b (m :: * -> *).
(Stream r ix a, Monad m) =>
(a -> m b) -> Array r ix a -> m ()
smapM_ a -> m b
f = forall (m :: * -> *) e a.
Monad m =>
(e -> m a) -> Steps m e -> m ()
S.mapM_ a -> m b
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) e. Monad m => Steps Id e -> Steps m e
S.transStepsId forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream
{-# INLINE smapM_ #-}

-- | Traverse a stream vector with a monadic index aware function, while discarding the result
--
-- ==== __Examples__
--
-- @since 0.5.0
simapM_
  :: forall r ix a b m
   . (S.Stream r ix a, Monad m)
  => (ix -> a -> m b)
  -> Array r ix a
  -> m ()
simapM_ :: forall r ix a b (m :: * -> *).
(Stream r ix a, Monad m) =>
(ix -> a -> m b) -> Array r ix a -> m ()
simapM_ ix -> a -> m b
f = forall (m :: * -> *) e a.
Monad m =>
(e -> m a) -> Steps m e -> m ()
S.mapM_ (forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry ix -> a -> m b
f) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) e. Monad m => Steps Id e -> Steps m e
S.transStepsId forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r ix e. Stream r ix e => Array r ix e -> Steps Id (ix, e)
S.toStreamIx
{-# INLINE simapM_ #-}

-- | Same as `smapM`, but with arguments flipped.
--
-- ==== __Examples__
--
-- @since 0.5.0
sforM
  :: forall r ix a b m
   . (S.Stream r ix a, Monad m)
  => Array r ix a
  -> (a -> m b)
  -> m (Vector DS b)
sforM :: forall r ix a b (m :: * -> *).
(Stream r ix a, Monad m) =>
Array r ix a -> (a -> m b) -> m (Vector DS b)
sforM = forall a b c. (a -> b -> c) -> b -> a -> c
flip forall r ix a b (m :: * -> *).
(Stream r ix a, Monad m) =>
(a -> m b) -> Array r ix a -> m (Vector DS b)
smapM
{-# INLINE sforM #-}

-- | Same as `simapM`, but with arguments flipped.
--
-- ==== __Examples__
--
-- @since 0.5.0
siforM
  :: forall r ix a b m
   . (S.Stream r ix a, Monad m)
  => Array r ix a
  -> (ix -> a -> m b)
  -> m (Vector DS b)
siforM :: forall r ix a b (m :: * -> *).
(Stream r ix a, Monad m) =>
Array r ix a -> (ix -> a -> m b) -> m (Vector DS b)
siforM = forall a b c. (a -> b -> c) -> b -> a -> c
flip forall r ix a b (m :: * -> *).
(Stream r ix a, Monad m) =>
(ix -> a -> m b) -> Array r ix a -> m (Vector DS b)
simapM
{-# INLINE siforM #-}

-- | Same as `smapM_`, but with arguments flipped.
--
-- ==== __Examples__
--
-- @since 0.5.0
sforM_ :: (S.Stream r ix a, Monad m) => Array r ix a -> (a -> m b) -> m ()
sforM_ :: forall r ix a (m :: * -> *) b.
(Stream r ix a, Monad m) =>
Array r ix a -> (a -> m b) -> m ()
sforM_ = forall a b c. (a -> b -> c) -> b -> a -> c
flip forall r ix a b (m :: * -> *).
(Stream r ix a, Monad m) =>
(a -> m b) -> Array r ix a -> m ()
smapM_
{-# INLINE sforM_ #-}

-- | Same as `simapM_`, but with arguments flipped.
--
-- ==== __Examples__
--
-- @since 0.5.0
siforM_
  :: forall r ix a b m
   . (S.Stream r ix a, Monad m)
  => Array r ix a
  -> (ix -> a -> m b)
  -> m ()
siforM_ :: forall r ix a b (m :: * -> *).
(Stream r ix a, Monad m) =>
Array r ix a -> (ix -> a -> m b) -> m ()
siforM_ = forall a b c. (a -> b -> c) -> b -> a -> c
flip forall r ix a b (m :: * -> *).
(Stream r ix a, Monad m) =>
(ix -> a -> m b) -> Array r ix a -> m ()
simapM_
{-# INLINE siforM_ #-}

-- | Zip two vectors together into a vector. The length of a resulting vector will
-- be the smallest length of the supplied vectors.
--
-- ==== __Examples__
--
-- @since 0.5.0
szip
  :: forall ra rb a b
   . (S.Stream ra Ix1 a, S.Stream rb Ix1 b)
  => Vector ra a
  -> Vector rb b
  -> Vector DS (a, b)
szip :: forall ra rb a b.
(Stream ra Int a, Stream rb Int b) =>
Vector ra a -> Vector rb b -> Vector DS (a, b)
szip = forall ra rb a b c.
(Stream ra Int a, Stream rb Int b) =>
(a -> b -> c) -> Vector ra a -> Vector rb b -> Vector DS c
szipWith (,)
{-# INLINE szip #-}

-- | Zip three vectors together into a vector. The length of a resulting vector will
-- be the smallest length of the supplied vectors.
--
-- @since 0.5.0
szip3
  :: forall ra rb rc a b c
   . (S.Stream ra Ix1 a, S.Stream rb Ix1 b, S.Stream rc Ix1 c)
  => Vector ra a
  -> Vector rb b
  -> Vector rc c
  -> Vector DS (a, b, c)
szip3 :: forall ra rb rc a b c.
(Stream ra Int a, Stream rb Int b, Stream rc Int c) =>
Vector ra a -> Vector rb b -> Vector rc c -> Vector DS (a, b, c)
szip3 = forall ra rb rc a b c d.
(Stream ra Int a, Stream rb Int b, Stream rc Int c) =>
(a -> b -> c -> d)
-> Vector ra a -> Vector rb b -> Vector rc c -> Vector DS d
szipWith3 (,,)
{-# INLINE szip3 #-}

-- | Zip four vectors together into a vector. The length of a resulting vector will
-- be the smallest length of the supplied vectors.
--
-- @since 0.5.0
szip4
  :: forall ra rb rc rd a b c d
   . (S.Stream ra Ix1 a, S.Stream rb Ix1 b, S.Stream rc Ix1 c, S.Stream rd Ix1 d)
  => Vector ra a
  -> Vector rb b
  -> Vector rc c
  -> Vector rd d
  -> Vector DS (a, b, c, d)
szip4 :: forall ra rb rc rd a b c d.
(Stream ra Int a, Stream rb Int b, Stream rc Int c,
 Stream rd Int d) =>
Vector ra a
-> Vector rb b
-> Vector rc c
-> Vector rd d
-> Vector DS (a, b, c, d)
szip4 = forall ra rb rc rd a b c d e.
(Stream ra Int a, Stream rb Int b, Stream rc Int c,
 Stream rd Int d) =>
(a -> b -> c -> d -> e)
-> Vector ra a
-> Vector rb b
-> Vector rc c
-> Vector rd d
-> Vector DS e
szipWith4 (,,,)
{-# INLINE szip4 #-}

-- | Zip five vectors together into a vector. The length of a resulting vector will
-- be the smallest length of the supplied vectors.
--
-- @since 0.5.0
szip5
  :: forall ra rb rc rd re a b c d e
   . (S.Stream ra Ix1 a, S.Stream rb Ix1 b, S.Stream rc Ix1 c, S.Stream rd Ix1 d, S.Stream re Ix1 e)
  => Vector ra a
  -> Vector rb b
  -> Vector rc c
  -> Vector rd d
  -> Vector re e
  -> Vector DS (a, b, c, d, e)
szip5 :: forall ra rb rc rd re a b c d e.
(Stream ra Int a, Stream rb Int b, Stream rc Int c,
 Stream rd Int d, Stream re Int e) =>
Vector ra a
-> Vector rb b
-> Vector rc c
-> Vector rd d
-> Vector re e
-> Vector DS (a, b, c, d, e)
szip5 = forall ra rb rc rd re a b c d e f.
(Stream ra Int a, Stream rb Int b, Stream rc Int c,
 Stream rd Int d, Stream re Int e) =>
(a -> b -> c -> d -> e -> f)
-> Vector ra a
-> Vector rb b
-> Vector rc c
-> Vector rd d
-> Vector re e
-> Vector DS f
szipWith5 (,,,,)
{-# INLINE szip5 #-}

-- | Zip six vectors together into a vector. The length of a resulting vector will
-- be the smallest length of the supplied vectors.
--
-- @since 0.5.0
szip6
  :: forall ra rb rc rd re rf a b c d e f
   . ( S.Stream ra Ix1 a
     , S.Stream rb Ix1 b
     , S.Stream rc Ix1 c
     , S.Stream rd Ix1 d
     , S.Stream re Ix1 e
     , S.Stream rf Ix1 f
     )
  => Vector ra a
  -> Vector rb b
  -> Vector rc c
  -> Vector rd d
  -> Vector re e
  -> Vector rf f
  -> Vector DS (a, b, c, d, e, f)
szip6 :: forall ra rb rc rd re rf a b c d e f.
(Stream ra Int a, Stream rb Int b, Stream rc Int c,
 Stream rd Int d, Stream re Int e, Stream rf Int f) =>
Vector ra a
-> Vector rb b
-> Vector rc c
-> Vector rd d
-> Vector re e
-> Vector rf f
-> Vector DS (a, b, c, d, e, f)
szip6 = forall ra rb rc rd re rf a b c d e f g.
(Stream ra Int a, Stream rb Int b, Stream rc Int c,
 Stream rd Int d, Stream re Int e, Stream rf Int f) =>
(a -> b -> c -> d -> e -> f -> g)
-> Vector ra a
-> Vector rb b
-> Vector rc c
-> Vector rd d
-> Vector re e
-> Vector rf f
-> Vector DS g
szipWith6 (,,,,,)
{-# INLINE szip6 #-}

-- | Zip two vectors together with a binary function into a vector. The length
-- of a resulting vector will be the smallest length of the supplied vectors.
--
-- ==== __Examples__
--
-- @since 0.5.0
szipWith
  :: forall ra rb a b c
   . (S.Stream ra Ix1 a, S.Stream rb Ix1 b)
  => (a -> b -> c)
  -> Vector ra a
  -> Vector rb b
  -> Vector DS c
szipWith :: forall ra rb a b c.
(Stream ra Int a, Stream rb Int b) =>
(a -> b -> c) -> Vector ra a -> Vector rb b -> Vector DS c
szipWith a -> b -> c
f Vector ra a
v1 Vector rb b
v2 = forall e. Steps Id e -> Vector DS e
fromSteps forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a b e.
Monad m =>
(a -> b -> e) -> Steps m a -> Steps m b -> Steps m e
S.zipWith a -> b -> c
f (forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream Vector ra a
v1) (forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream Vector rb b
v2)
{-# INLINE szipWith #-}

-- | Zip three vectors together with a ternary function into a vector. The length
-- of a resulting vector will be the smallest length of the supplied vectors.
--
-- @since 0.5.0
szipWith3
  :: forall ra rb rc a b c d
   . (S.Stream ra Ix1 a, S.Stream rb Ix1 b, S.Stream rc Ix1 c)
  => (a -> b -> c -> d)
  -> Vector ra a
  -> Vector rb b
  -> Vector rc c
  -> Vector DS d
szipWith3 :: forall ra rb rc a b c d.
(Stream ra Int a, Stream rb Int b, Stream rc Int c) =>
(a -> b -> c -> d)
-> Vector ra a -> Vector rb b -> Vector rc c -> Vector DS d
szipWith3 a -> b -> c -> d
f Vector ra a
v1 Vector rb b
v2 Vector rc c
v3 = forall e. Steps Id e -> Vector DS e
fromSteps forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a b c d.
Monad m =>
(a -> b -> c -> d)
-> Steps m a -> Steps m b -> Steps m c -> Steps m d
S.zipWith3 a -> b -> c -> d
f (forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream Vector ra a
v1) (forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream Vector rb b
v2) (forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream Vector rc c
v3)
{-# INLINE szipWith3 #-}

-- | Zip four vectors together with a quaternary function into a vector. The length
-- of a resulting vector will be the smallest length of the supplied vectors.
--
-- @since 0.5.0
szipWith4
  :: forall ra rb rc rd a b c d e
   . (S.Stream ra Ix1 a, S.Stream rb Ix1 b, S.Stream rc Ix1 c, S.Stream rd Ix1 d)
  => (a -> b -> c -> d -> e)
  -> Vector ra a
  -> Vector rb b
  -> Vector rc c
  -> Vector rd d
  -> Vector DS e
szipWith4 :: forall ra rb rc rd a b c d e.
(Stream ra Int a, Stream rb Int b, Stream rc Int c,
 Stream rd Int d) =>
(a -> b -> c -> d -> e)
-> Vector ra a
-> Vector rb b
-> Vector rc c
-> Vector rd d
-> Vector DS e
szipWith4 a -> b -> c -> d -> e
f Vector ra a
v1 Vector rb b
v2 Vector rc c
v3 Vector rd d
v4 =
  forall e. Steps Id e -> Vector DS e
fromSteps forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a b c d e.
Monad m =>
(a -> b -> c -> d -> e)
-> Steps m a -> Steps m b -> Steps m c -> Steps m d -> Steps m e
S.zipWith4 a -> b -> c -> d -> e
f (forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream Vector ra a
v1) (forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream Vector rb b
v2) (forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream Vector rc c
v3) (forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream Vector rd d
v4)
{-# INLINE szipWith4 #-}

-- | Zip five vectors together with a quinary function into a vector. The length
-- of a resulting vector will be the smallest length of the supplied vectors.
--
-- @since 0.5.0
szipWith5
  :: forall ra rb rc rd re a b c d e f
   . (S.Stream ra Ix1 a, S.Stream rb Ix1 b, S.Stream rc Ix1 c, S.Stream rd Ix1 d, S.Stream re Ix1 e)
  => (a -> b -> c -> d -> e -> f)
  -> Vector ra a
  -> Vector rb b
  -> Vector rc c
  -> Vector rd d
  -> Vector re e
  -> Vector DS f
szipWith5 :: forall ra rb rc rd re a b c d e f.
(Stream ra Int a, Stream rb Int b, Stream rc Int c,
 Stream rd Int d, Stream re Int e) =>
(a -> b -> c -> d -> e -> f)
-> Vector ra a
-> Vector rb b
-> Vector rc c
-> Vector rd d
-> Vector re e
-> Vector DS f
szipWith5 a -> b -> c -> d -> e -> f
f Vector ra a
v1 Vector rb b
v2 Vector rc c
v3 Vector rd d
v4 Vector re e
v5 =
  forall e. Steps Id e -> Vector DS e
fromSteps forall a b. (a -> b) -> a -> b
$
    forall (m :: * -> *) a b c d e f.
Monad m =>
(a -> b -> c -> d -> e -> f)
-> Steps m a
-> Steps m b
-> Steps m c
-> Steps m d
-> Steps m e
-> Steps m f
S.zipWith5 a -> b -> c -> d -> e -> f
f (forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream Vector ra a
v1) (forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream Vector rb b
v2) (forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream Vector rc c
v3) (forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream Vector rd d
v4) (forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream Vector re e
v5)
{-# INLINE szipWith5 #-}

-- | Zip six vectors together with a senary function into a vector. The length
-- of a resulting vector will be the smallest length of the supplied vectors.
--
-- @since 0.5.0
szipWith6
  :: forall ra rb rc rd re rf a b c d e f g
   . ( S.Stream ra Ix1 a
     , S.Stream rb Ix1 b
     , S.Stream rc Ix1 c
     , S.Stream rd Ix1 d
     , S.Stream re Ix1 e
     , S.Stream rf Ix1 f
     )
  => (a -> b -> c -> d -> e -> f -> g)
  -> Vector ra a
  -> Vector rb b
  -> Vector rc c
  -> Vector rd d
  -> Vector re e
  -> Vector rf f
  -> Vector DS g
szipWith6 :: forall ra rb rc rd re rf a b c d e f g.
(Stream ra Int a, Stream rb Int b, Stream rc Int c,
 Stream rd Int d, Stream re Int e, Stream rf Int f) =>
(a -> b -> c -> d -> e -> f -> g)
-> Vector ra a
-> Vector rb b
-> Vector rc c
-> Vector rd d
-> Vector re e
-> Vector rf f
-> Vector DS g
szipWith6 a -> b -> c -> d -> e -> f -> g
f Vector ra a
v1 Vector rb b
v2 Vector rc c
v3 Vector rd d
v4 Vector re e
v5 Vector rf f
v6 =
  forall e. Steps Id e -> Vector DS e
fromSteps forall a b. (a -> b) -> a -> b
$
    forall (m :: * -> *) a b c d e f g.
Monad m =>
(a -> b -> c -> d -> e -> f -> g)
-> Steps m a
-> Steps m b
-> Steps m c
-> Steps m d
-> Steps m e
-> Steps m f
-> Steps m g
S.zipWith6
      a -> b -> c -> d -> e -> f -> g
f
      (forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream Vector ra a
v1)
      (forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream Vector rb b
v2)
      (forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream Vector rc c
v3)
      (forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream Vector rd d
v4)
      (forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream Vector re e
v5)
      (forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream Vector rf f
v6)
{-# INLINE szipWith6 #-}

-- | Just like `szipWith`, zip two vectors together, but with an index aware
-- function. The length of a resulting vector will be the smallest length of the
-- supplied vectors.
--
-- ==== __Examples__
--
-- @since 0.5.0
sizipWith
  :: forall ra rb a b c
   . (S.Stream ra Ix1 a, S.Stream rb Ix1 b)
  => (Ix1 -> a -> b -> c)
  -> Vector ra a
  -> Vector rb b
  -> Vector DS c
sizipWith :: forall ra rb a b c.
(Stream ra Int a, Stream rb Int b) =>
(Int -> a -> b -> c) -> Vector ra a -> Vector rb b -> Vector DS c
sizipWith Int -> a -> b -> c
f Vector ra a
v1 Vector rb b
v2 = forall e. Steps Id e -> Vector DS e
fromSteps forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a b e.
Monad m =>
(a -> b -> e) -> Steps m a -> Steps m b -> Steps m e
S.zipWith (forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Int -> a -> b -> c
f) (forall r ix e. Stream r ix e => Array r ix e -> Steps Id (ix, e)
S.toStreamIx Vector ra a
v1) (forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream Vector rb b
v2)
{-# INLINE sizipWith #-}

-- | Just like `szipWith3`, zip three vectors together, but with an index aware
-- function. The length of a resulting vector will be the smallest length of the
-- supplied vectors.
--
-- @since 0.5.0
sizipWith3
  :: forall ra rb rc a b c d
   . (S.Stream ra Ix1 a, S.Stream rb Ix1 b, S.Stream rc Ix1 c)
  => (Ix1 -> a -> b -> c -> d)
  -> Vector ra a
  -> Vector rb b
  -> Vector rc c
  -> Vector DS d
sizipWith3 :: forall ra rb rc a b c d.
(Stream ra Int a, Stream rb Int b, Stream rc Int c) =>
(Int -> a -> b -> c -> d)
-> Vector ra a -> Vector rb b -> Vector rc c -> Vector DS d
sizipWith3 Int -> a -> b -> c -> d
f Vector ra a
v1 Vector rb b
v2 Vector rc c
v3 =
  forall e. Steps Id e -> Vector DS e
fromSteps forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a b c d.
Monad m =>
(a -> b -> c -> d)
-> Steps m a -> Steps m b -> Steps m c -> Steps m d
S.zipWith3 (forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Int -> a -> b -> c -> d
f) (forall r ix e. Stream r ix e => Array r ix e -> Steps Id (ix, e)
S.toStreamIx Vector ra a
v1) (forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream Vector rb b
v2) (forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream Vector rc c
v3)
{-# INLINE sizipWith3 #-}

-- | Just like `szipWith4`, zip four vectors together, but with an index aware
-- function. The length of a resulting vector will be the smallest
-- length of the supplied vectors.
--
-- @since 0.5.0
sizipWith4
  :: forall ra rb rc rd a b c d e
   . (S.Stream ra Ix1 a, S.Stream rb Ix1 b, S.Stream rc Ix1 c, S.Stream rd Ix1 d)
  => (Ix1 -> a -> b -> c -> d -> e)
  -> Vector ra a
  -> Vector rb b
  -> Vector rc c
  -> Vector rd d
  -> Vector DS e
sizipWith4 :: forall ra rb rc rd a b c d e.
(Stream ra Int a, Stream rb Int b, Stream rc Int c,
 Stream rd Int d) =>
(Int -> a -> b -> c -> d -> e)
-> Vector ra a
-> Vector rb b
-> Vector rc c
-> Vector rd d
-> Vector DS e
sizipWith4 Int -> a -> b -> c -> d -> e
f Vector ra a
v1 Vector rb b
v2 Vector rc c
v3 Vector rd d
v4 =
  forall e. Steps Id e -> Vector DS e
fromSteps forall a b. (a -> b) -> a -> b
$
    forall (m :: * -> *) a b c d e.
Monad m =>
(a -> b -> c -> d -> e)
-> Steps m a -> Steps m b -> Steps m c -> Steps m d -> Steps m e
S.zipWith4 (forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Int -> a -> b -> c -> d -> e
f) (forall r ix e. Stream r ix e => Array r ix e -> Steps Id (ix, e)
S.toStreamIx Vector ra a
v1) (forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream Vector rb b
v2) (forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream Vector rc c
v3) (forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream Vector rd d
v4)
{-# INLINE sizipWith4 #-}

-- | Just like `szipWith5`, zip five vectors together, but with an index aware
-- function. The length of a resulting vector will be the smallest length of the
-- supplied vectors.
--
-- @since 0.5.0
sizipWith5
  :: forall ra rb rc rd re a b c d e f
   . (S.Stream ra Ix1 a, S.Stream rb Ix1 b, S.Stream rc Ix1 c, S.Stream rd Ix1 d, S.Stream re Ix1 e)
  => (Ix1 -> a -> b -> c -> d -> e -> f)
  -> Vector ra a
  -> Vector rb b
  -> Vector rc c
  -> Vector rd d
  -> Vector re e
  -> Vector DS f
sizipWith5 :: forall ra rb rc rd re a b c d e f.
(Stream ra Int a, Stream rb Int b, Stream rc Int c,
 Stream rd Int d, Stream re Int e) =>
(Int -> a -> b -> c -> d -> e -> f)
-> Vector ra a
-> Vector rb b
-> Vector rc c
-> Vector rd d
-> Vector re e
-> Vector DS f
sizipWith5 Int -> a -> b -> c -> d -> e -> f
f Vector ra a
v1 Vector rb b
v2 Vector rc c
v3 Vector rd d
v4 Vector re e
v5 =
  forall e. Steps Id e -> Vector DS e
fromSteps forall a b. (a -> b) -> a -> b
$
    forall (m :: * -> *) a b c d e f.
Monad m =>
(a -> b -> c -> d -> e -> f)
-> Steps m a
-> Steps m b
-> Steps m c
-> Steps m d
-> Steps m e
-> Steps m f
S.zipWith5
      (forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Int -> a -> b -> c -> d -> e -> f
f)
      (forall r ix e. Stream r ix e => Array r ix e -> Steps Id (ix, e)
S.toStreamIx Vector ra a
v1)
      (forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream Vector rb b
v2)
      (forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream Vector rc c
v3)
      (forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream Vector rd d
v4)
      (forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream Vector re e
v5)
{-# INLINE sizipWith5 #-}

-- | Just like `szipWith6`, zip six vectors together, but with an index aware
-- function. The length of a resulting vector will be the smallest length of the
-- supplied vectors.
--
-- @since 0.5.0
sizipWith6
  :: forall ra rb rc rd re rf a b c d e f g
   . ( S.Stream ra Ix1 a
     , S.Stream rb Ix1 b
     , S.Stream rc Ix1 c
     , S.Stream rd Ix1 d
     , S.Stream re Ix1 e
     , S.Stream rf Ix1 f
     )
  => (Ix1 -> a -> b -> c -> d -> e -> f -> g)
  -> Vector ra a
  -> Vector rb b
  -> Vector rc c
  -> Vector rd d
  -> Vector re e
  -> Vector rf f
  -> Vector DS g
sizipWith6 :: forall ra rb rc rd re rf a b c d e f g.
(Stream ra Int a, Stream rb Int b, Stream rc Int c,
 Stream rd Int d, Stream re Int e, Stream rf Int f) =>
(Int -> a -> b -> c -> d -> e -> f -> g)
-> Vector ra a
-> Vector rb b
-> Vector rc c
-> Vector rd d
-> Vector re e
-> Vector rf f
-> Vector DS g
sizipWith6 Int -> a -> b -> c -> d -> e -> f -> g
f Vector ra a
v1 Vector rb b
v2 Vector rc c
v3 Vector rd d
v4 Vector re e
v5 Vector rf f
v6 =
  forall e. Steps Id e -> Vector DS e
fromSteps forall a b. (a -> b) -> a -> b
$
    forall (m :: * -> *) a b c d e f g.
Monad m =>
(a -> b -> c -> d -> e -> f -> g)
-> Steps m a
-> Steps m b
-> Steps m c
-> Steps m d
-> Steps m e
-> Steps m f
-> Steps m g
S.zipWith6
      (forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Int -> a -> b -> c -> d -> e -> f -> g
f)
      (forall r ix e. Stream r ix e => Array r ix e -> Steps Id (ix, e)
S.toStreamIx Vector ra a
v1)
      (forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream Vector rb b
v2)
      (forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream Vector rc c
v3)
      (forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream Vector rd d
v4)
      (forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream Vector re e
v5)
      (forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream Vector rf f
v6)
{-# INLINE sizipWith6 #-}

-- | Zip two vectors together with a binary monadic action into a vector. The
-- length of a resulting vector will be the smallest length of the supplied
-- vectors.
--
-- ==== __Examples__
--
-- @since 0.5.0
szipWithM
  :: forall ra rb a b c m
   . (S.Stream ra Ix1 a, S.Stream rb Ix1 b, Monad m)
  => (a -> b -> m c)
  -> Vector ra a
  -> Vector rb b
  -> m (Vector DS c)
szipWithM :: forall ra rb a b c (m :: * -> *).
(Stream ra Int a, Stream rb Int b, Monad m) =>
(a -> b -> m c) -> Vector ra a -> Vector rb b -> m (Vector DS c)
szipWithM a -> b -> m c
f Vector ra a
v1 Vector rb b
v2 = forall (m :: * -> *) e. Monad m => Steps m e -> m (Vector DS e)
fromStepsM forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a b c.
Monad m =>
(a -> b -> m c) -> Steps m a -> Steps m b -> Steps m c
S.zipWithM a -> b -> m c
f (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector ra a
v1) (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rb b
v2)
{-# INLINE szipWithM #-}

-- | Zip three vectors together with a ternary monadic action into a vector. The
-- length of a resulting vector will be the smallest length of the supplied
-- vectors.
--
-- @since 0.5.0
szipWith3M
  :: forall ra rb rc a b c d m
   . (S.Stream ra Ix1 a, S.Stream rb Ix1 b, S.Stream rc Ix1 c, Monad m)
  => (a -> b -> c -> m d)
  -> Vector ra a
  -> Vector rb b
  -> Vector rc c
  -> m (Vector DS d)
szipWith3M :: forall ra rb rc a b c d (m :: * -> *).
(Stream ra Int a, Stream rb Int b, Stream rc Int c, Monad m) =>
(a -> b -> c -> m d)
-> Vector ra a -> Vector rb b -> Vector rc c -> m (Vector DS d)
szipWith3M a -> b -> c -> m d
f Vector ra a
v1 Vector rb b
v2 Vector rc c
v3 = forall (m :: * -> *) e. Monad m => Steps m e -> m (Vector DS e)
fromStepsM forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a b c d.
Monad m =>
(a -> b -> c -> m d)
-> Steps m a -> Steps m b -> Steps m c -> Steps m d
S.zipWith3M a -> b -> c -> m d
f (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector ra a
v1) (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rb b
v2) (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rc c
v3)
{-# INLINE szipWith3M #-}

-- | Zip four vectors together with a quaternary monadic action into a vector. The
-- length of a resulting vector will be the smallest length of the supplied
-- vectors.
--
-- @since 0.5.0
szipWith4M
  :: forall ra rb rc rd a b c d e m
   . (S.Stream ra Ix1 a, S.Stream rb Ix1 b, S.Stream rc Ix1 c, S.Stream rd Ix1 d, Monad m)
  => (a -> b -> c -> d -> m e)
  -> Vector ra a
  -> Vector rb b
  -> Vector rc c
  -> Vector rd d
  -> m (Vector DS e)
szipWith4M :: forall ra rb rc rd a b c d e (m :: * -> *).
(Stream ra Int a, Stream rb Int b, Stream rc Int c,
 Stream rd Int d, Monad m) =>
(a -> b -> c -> d -> m e)
-> Vector ra a
-> Vector rb b
-> Vector rc c
-> Vector rd d
-> m (Vector DS e)
szipWith4M a -> b -> c -> d -> m e
f Vector ra a
v1 Vector rb b
v2 Vector rc c
v3 Vector rd d
v4 =
  forall (m :: * -> *) e. Monad m => Steps m e -> m (Vector DS e)
fromStepsM forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a b c d e.
Monad m =>
(a -> b -> c -> d -> m e)
-> Steps m a -> Steps m b -> Steps m c -> Steps m d -> Steps m e
S.zipWith4M a -> b -> c -> d -> m e
f (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector ra a
v1) (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rb b
v2) (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rc c
v3) (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rd d
v4)
{-# INLINE szipWith4M #-}

-- | Zip five vectors together with a quinary monadic action into a vector. The
-- length of a resulting vector will be the smallest length of the supplied
-- vectors.
--
-- @since 0.5.0
szipWith5M
  :: forall ra rb rc rd re a b c d e f m
   . ( S.Stream ra Ix1 a
     , S.Stream rb Ix1 b
     , S.Stream rc Ix1 c
     , S.Stream rd Ix1 d
     , S.Stream re Ix1 e
     , Monad m
     )
  => (a -> b -> c -> d -> e -> m f)
  -> Vector ra a
  -> Vector rb b
  -> Vector rc c
  -> Vector rd d
  -> Vector re e
  -> m (Vector DS f)
szipWith5M :: forall ra rb rc rd re a b c d e f (m :: * -> *).
(Stream ra Int a, Stream rb Int b, Stream rc Int c,
 Stream rd Int d, Stream re Int e, Monad m) =>
(a -> b -> c -> d -> e -> m f)
-> Vector ra a
-> Vector rb b
-> Vector rc c
-> Vector rd d
-> Vector re e
-> m (Vector DS f)
szipWith5M a -> b -> c -> d -> e -> m f
f Vector ra a
v1 Vector rb b
v2 Vector rc c
v3 Vector rd d
v4 Vector re e
v5 =
  forall (m :: * -> *) e. Monad m => Steps m e -> m (Vector DS e)
fromStepsM forall a b. (a -> b) -> a -> b
$
    forall (m :: * -> *) a b c d e f.
Monad m =>
(a -> b -> c -> d -> e -> m f)
-> Steps m a
-> Steps m b
-> Steps m c
-> Steps m d
-> Steps m e
-> Steps m f
S.zipWith5M a -> b -> c -> d -> e -> m f
f (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector ra a
v1) (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rb b
v2) (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rc c
v3) (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rd d
v4) (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector re e
v5)
{-# INLINE szipWith5M #-}

-- | Zip six vectors together with a senary monadic action into a vector. The
-- length of a resulting vector will be the smallest length of the supplied
-- vectors.
--
-- @since 0.5.0
szipWith6M
  :: forall ra rb rc rd re rf a b c d e f g m
   . ( S.Stream ra Ix1 a
     , S.Stream rb Ix1 b
     , S.Stream rc Ix1 c
     , S.Stream rd Ix1 d
     , S.Stream re Ix1 e
     , S.Stream rf Ix1 f
     , Monad m
     )
  => (a -> b -> c -> d -> e -> f -> m g)
  -> Vector ra a
  -> Vector rb b
  -> Vector rc c
  -> Vector rd d
  -> Vector re e
  -> Vector rf f
  -> m (Vector DS g)
szipWith6M :: forall ra rb rc rd re rf a b c d e f g (m :: * -> *).
(Stream ra Int a, Stream rb Int b, Stream rc Int c,
 Stream rd Int d, Stream re Int e, Stream rf Int f, Monad m) =>
(a -> b -> c -> d -> e -> f -> m g)
-> Vector ra a
-> Vector rb b
-> Vector rc c
-> Vector rd d
-> Vector re e
-> Vector rf f
-> m (Vector DS g)
szipWith6M a -> b -> c -> d -> e -> f -> m g
f Vector ra a
v1 Vector rb b
v2 Vector rc c
v3 Vector rd d
v4 Vector re e
v5 Vector rf f
v6 =
  forall (m :: * -> *) e. Monad m => Steps m e -> m (Vector DS e)
fromStepsM forall a b. (a -> b) -> a -> b
$
    forall (m :: * -> *) a b c d e f g.
Monad m =>
(a -> b -> c -> d -> e -> f -> m g)
-> Steps m a
-> Steps m b
-> Steps m c
-> Steps m d
-> Steps m e
-> Steps m f
-> Steps m g
S.zipWith6M
      a -> b -> c -> d -> e -> f -> m g
f
      (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector ra a
v1)
      (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rb b
v2)
      (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rc c
v3)
      (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rd d
v4)
      (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector re e
v5)
      (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rf f
v6)
{-# INLINE szipWith6M #-}

-- | Just like `szipWithM`, zip two vectors together, but with an index aware
-- monadic action. The length of a resulting vector will be the smallest length of the
-- supplied vectors.
--
-- ==== __Examples__
--
-- @since 0.5.0
sizipWithM
  :: forall ra rb a b c m
   . (S.Stream ra Ix1 a, S.Stream rb Ix1 b, Monad m)
  => (Ix1 -> a -> b -> m c)
  -> Vector ra a
  -> Vector rb b
  -> m (Vector DS c)
sizipWithM :: forall ra rb a b c (m :: * -> *).
(Stream ra Int a, Stream rb Int b, Monad m) =>
(Int -> a -> b -> m c)
-> Vector ra a -> Vector rb b -> m (Vector DS c)
sizipWithM Int -> a -> b -> m c
f Vector ra a
v1 Vector rb b
v2 = forall (m :: * -> *) e. Monad m => Steps m e -> m (Vector DS e)
fromStepsM forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a b c.
Monad m =>
(a -> b -> m c) -> Steps m a -> Steps m b -> Steps m c
S.zipWithM (forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Int -> a -> b -> m c
f) (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m (ix, e)
toStreamIxM Vector ra a
v1) (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rb b
v2)
{-# INLINE sizipWithM #-}

-- | Just like `szipWith3M`, zip three vectors together, but with an index aware
-- monadic action. The length of a resulting vector will be the smallest length of the
-- supplied vectors.
--
-- @since 0.5.0
sizipWith3M
  :: forall ra rb rc a b c d m
   . (S.Stream ra Ix1 a, S.Stream rb Ix1 b, S.Stream rc Ix1 c, Monad m)
  => (Ix1 -> a -> b -> c -> m d)
  -> Vector ra a
  -> Vector rb b
  -> Vector rc c
  -> m (Vector DS d)
sizipWith3M :: forall ra rb rc a b c d (m :: * -> *).
(Stream ra Int a, Stream rb Int b, Stream rc Int c, Monad m) =>
(Int -> a -> b -> c -> m d)
-> Vector ra a -> Vector rb b -> Vector rc c -> m (Vector DS d)
sizipWith3M Int -> a -> b -> c -> m d
f Vector ra a
v1 Vector rb b
v2 Vector rc c
v3 =
  forall (m :: * -> *) e. Monad m => Steps m e -> m (Vector DS e)
fromStepsM forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a b c d.
Monad m =>
(a -> b -> c -> m d)
-> Steps m a -> Steps m b -> Steps m c -> Steps m d
S.zipWith3M (forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Int -> a -> b -> c -> m d
f) (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m (ix, e)
toStreamIxM Vector ra a
v1) (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rb b
v2) (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rc c
v3)
{-# INLINE sizipWith3M #-}

-- | Just like `szipWith4M`, zip four vectors together, but with an index aware
-- monadic action. The length of a resulting vector will be the smallest length of the
-- supplied vectors.
--
-- @since 0.5.0
sizipWith4M
  :: forall ra rb rc rd a b c d e m
   . (S.Stream ra Ix1 a, S.Stream rb Ix1 b, S.Stream rc Ix1 c, S.Stream rd Ix1 d, Monad m)
  => (Ix1 -> a -> b -> c -> d -> m e)
  -> Vector ra a
  -> Vector rb b
  -> Vector rc c
  -> Vector rd d
  -> m (Vector DS e)
sizipWith4M :: forall ra rb rc rd a b c d e (m :: * -> *).
(Stream ra Int a, Stream rb Int b, Stream rc Int c,
 Stream rd Int d, Monad m) =>
(Int -> a -> b -> c -> d -> m e)
-> Vector ra a
-> Vector rb b
-> Vector rc c
-> Vector rd d
-> m (Vector DS e)
sizipWith4M Int -> a -> b -> c -> d -> m e
f Vector ra a
v1 Vector rb b
v2 Vector rc c
v3 Vector rd d
v4 =
  forall (m :: * -> *) e. Monad m => Steps m e -> m (Vector DS e)
fromStepsM forall a b. (a -> b) -> a -> b
$
    forall (m :: * -> *) a b c d e.
Monad m =>
(a -> b -> c -> d -> m e)
-> Steps m a -> Steps m b -> Steps m c -> Steps m d -> Steps m e
S.zipWith4M (forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Int -> a -> b -> c -> d -> m e
f) (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m (ix, e)
toStreamIxM Vector ra a
v1) (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rb b
v2) (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rc c
v3) (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rd d
v4)
{-# INLINE sizipWith4M #-}

-- | Just like `szipWith6M`, zip five vectors together, but with an index aware
-- monadic action. The length of a resulting vector will be the smallest length of the
-- supplied vectors.
--
-- @since 0.5.0
sizipWith5M
  :: forall ra rb rc rd re a b c d e f m
   . ( S.Stream ra Ix1 a
     , S.Stream rb Ix1 b
     , S.Stream rc Ix1 c
     , S.Stream rd Ix1 d
     , S.Stream re Ix1 e
     , Monad m
     )
  => (Ix1 -> a -> b -> c -> d -> e -> m f)
  -> Vector ra a
  -> Vector rb b
  -> Vector rc c
  -> Vector rd d
  -> Vector re e
  -> m (Vector DS f)
sizipWith5M :: forall ra rb rc rd re a b c d e f (m :: * -> *).
(Stream ra Int a, Stream rb Int b, Stream rc Int c,
 Stream rd Int d, Stream re Int e, Monad m) =>
(Int -> a -> b -> c -> d -> e -> m f)
-> Vector ra a
-> Vector rb b
-> Vector rc c
-> Vector rd d
-> Vector re e
-> m (Vector DS f)
sizipWith5M Int -> a -> b -> c -> d -> e -> m f
f Vector ra a
v1 Vector rb b
v2 Vector rc c
v3 Vector rd d
v4 Vector re e
v5 =
  forall (m :: * -> *) e. Monad m => Steps m e -> m (Vector DS e)
fromStepsM forall a b. (a -> b) -> a -> b
$
    forall (m :: * -> *) a b c d e f.
Monad m =>
(a -> b -> c -> d -> e -> m f)
-> Steps m a
-> Steps m b
-> Steps m c
-> Steps m d
-> Steps m e
-> Steps m f
S.zipWith5M
      (forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Int -> a -> b -> c -> d -> e -> m f
f)
      (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m (ix, e)
toStreamIxM Vector ra a
v1)
      (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rb b
v2)
      (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rc c
v3)
      (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rd d
v4)
      (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector re e
v5)
{-# INLINE sizipWith5M #-}

-- | Just like `szipWith6M`, zip six vectors together, but with an index aware
-- monadic action. The length of a resulting vector will be the smallest length of the
-- supplied vectors.
--
-- ==== __Examples__
--
-- @since 0.5.0
sizipWith6M
  :: forall ra rb rc rd re rf a b c d e f g m
   . ( S.Stream ra Ix1 a
     , S.Stream rb Ix1 b
     , S.Stream rc Ix1 c
     , S.Stream rd Ix1 d
     , S.Stream re Ix1 e
     , S.Stream rf Ix1 f
     , Monad m
     )
  => (Ix1 -> a -> b -> c -> d -> e -> f -> m g)
  -> Vector ra a
  -> Vector rb b
  -> Vector rc c
  -> Vector rd d
  -> Vector re e
  -> Vector rf f
  -> m (Vector DS g)
sizipWith6M :: forall ra rb rc rd re rf a b c d e f g (m :: * -> *).
(Stream ra Int a, Stream rb Int b, Stream rc Int c,
 Stream rd Int d, Stream re Int e, Stream rf Int f, Monad m) =>
(Int -> a -> b -> c -> d -> e -> f -> m g)
-> Vector ra a
-> Vector rb b
-> Vector rc c
-> Vector rd d
-> Vector re e
-> Vector rf f
-> m (Vector DS g)
sizipWith6M Int -> a -> b -> c -> d -> e -> f -> m g
f Vector ra a
v1 Vector rb b
v2 Vector rc c
v3 Vector rd d
v4 Vector re e
v5 Vector rf f
v6 =
  forall (m :: * -> *) e. Monad m => Steps m e -> m (Vector DS e)
fromStepsM forall a b. (a -> b) -> a -> b
$
    forall (m :: * -> *) a b c d e f g.
Monad m =>
(a -> b -> c -> d -> e -> f -> m g)
-> Steps m a
-> Steps m b
-> Steps m c
-> Steps m d
-> Steps m e
-> Steps m f
-> Steps m g
S.zipWith6M
      (forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Int -> a -> b -> c -> d -> e -> f -> m g
f)
      (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m (ix, e)
toStreamIxM Vector ra a
v1)
      (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rb b
v2)
      (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rc c
v3)
      (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rd d
v4)
      (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector re e
v5)
      (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rf f
v6)
{-# INLINE sizipWith6M #-}

-- | Similar to `szipWithM`, zip two vectors together with a binary monadic
-- action, while discarding its result. The action will be invoked as many times as
-- the length of the smallest vector.
--
-- ==== __Examples__
--
-- @since 0.5.0
szipWithM_
  :: forall ra rb a b c m
   . (S.Stream ra Ix1 a, S.Stream rb Ix1 b, Monad m)
  => (a -> b -> m c)
  -> Vector ra a
  -> Vector rb b
  -> m ()
szipWithM_ :: forall ra rb a b c (m :: * -> *).
(Stream ra Int a, Stream rb Int b, Monad m) =>
(a -> b -> m c) -> Vector ra a -> Vector rb b -> m ()
szipWithM_ a -> b -> m c
f Vector ra a
v1 Vector rb b
v2 = forall (m :: * -> *) a b c.
Monad m =>
(a -> b -> m c) -> Steps m a -> Steps m b -> m ()
S.zipWithM_ a -> b -> m c
f (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector ra a
v1) (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rb b
v2)
{-# INLINE szipWithM_ #-}

-- | Similar to `szipWith3M`, zip three vectors together with a ternary monadic
-- action, while discarding its result. The action will be invoked as many times as
-- the length of the smallest vector.
--
-- @since 0.5.0
szipWith3M_
  :: forall ra rb rc a b c d m
   . (S.Stream ra Ix1 a, S.Stream rb Ix1 b, S.Stream rc Ix1 c, Monad m)
  => (a -> b -> c -> m d)
  -> Vector ra a
  -> Vector rb b
  -> Vector rc c
  -> m ()
szipWith3M_ :: forall ra rb rc a b c d (m :: * -> *).
(Stream ra Int a, Stream rb Int b, Stream rc Int c, Monad m) =>
(a -> b -> c -> m d)
-> Vector ra a -> Vector rb b -> Vector rc c -> m ()
szipWith3M_ a -> b -> c -> m d
f Vector ra a
v1 Vector rb b
v2 Vector rc c
v3 = forall (m :: * -> *) a b c d.
Monad m =>
(a -> b -> c -> m d) -> Steps m a -> Steps m b -> Steps m c -> m ()
S.zipWith3M_ a -> b -> c -> m d
f (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector ra a
v1) (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rb b
v2) (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rc c
v3)
{-# INLINE szipWith3M_ #-}

-- | Similar to `szipWith4M`, zip four vectors together with a quaternary monadic
-- action, while discarding its result. The action will be invoked as many times as
-- the length of the smallest vector.
--
-- @since 0.5.0
szipWith4M_
  :: forall ra rb rc rd a b c d e m
   . (S.Stream ra Ix1 a, S.Stream rb Ix1 b, S.Stream rc Ix1 c, S.Stream rd Ix1 d, Monad m)
  => (a -> b -> c -> d -> m e)
  -> Vector ra a
  -> Vector rb b
  -> Vector rc c
  -> Vector rd d
  -> m ()
szipWith4M_ :: forall ra rb rc rd a b c d e (m :: * -> *).
(Stream ra Int a, Stream rb Int b, Stream rc Int c,
 Stream rd Int d, Monad m) =>
(a -> b -> c -> d -> m e)
-> Vector ra a -> Vector rb b -> Vector rc c -> Vector rd d -> m ()
szipWith4M_ a -> b -> c -> d -> m e
f Vector ra a
v1 Vector rb b
v2 Vector rc c
v3 Vector rd d
v4 =
  forall (m :: * -> *) a b c d e.
Monad m =>
(a -> b -> c -> d -> m e)
-> Steps m a -> Steps m b -> Steps m c -> Steps m d -> m ()
S.zipWith4M_ a -> b -> c -> d -> m e
f (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector ra a
v1) (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rb b
v2) (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rc c
v3) (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rd d
v4)
{-# INLINE szipWith4M_ #-}

-- | Similar to `szipWith5M`, zip five vectors together with a quinary monadic
-- action, while discarding its result. The action will be invoked as many times as
-- the length of the smallest vector.
--
-- @since 0.5.0
szipWith5M_
  :: forall ra rb rc rd re a b c d e f m
   . ( S.Stream ra Ix1 a
     , S.Stream rb Ix1 b
     , S.Stream rc Ix1 c
     , S.Stream rd Ix1 d
     , S.Stream re Ix1 e
     , Monad m
     )
  => (a -> b -> c -> d -> e -> m f)
  -> Vector ra a
  -> Vector rb b
  -> Vector rc c
  -> Vector rd d
  -> Vector re e
  -> m ()
szipWith5M_ :: forall ra rb rc rd re a b c d e f (m :: * -> *).
(Stream ra Int a, Stream rb Int b, Stream rc Int c,
 Stream rd Int d, Stream re Int e, Monad m) =>
(a -> b -> c -> d -> e -> m f)
-> Vector ra a
-> Vector rb b
-> Vector rc c
-> Vector rd d
-> Vector re e
-> m ()
szipWith5M_ a -> b -> c -> d -> e -> m f
f Vector ra a
v1 Vector rb b
v2 Vector rc c
v3 Vector rd d
v4 Vector re e
v5 =
  forall (m :: * -> *) a b c d e f.
Monad m =>
(a -> b -> c -> d -> e -> m f)
-> Steps m a
-> Steps m b
-> Steps m c
-> Steps m d
-> Steps m e
-> m ()
S.zipWith5M_ a -> b -> c -> d -> e -> m f
f (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector ra a
v1) (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rb b
v2) (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rc c
v3) (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rd d
v4) (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector re e
v5)
{-# INLINE szipWith5M_ #-}

-- | Similar to `szipWith6M`, zip six vectors together with a senary monadic
-- action, while discarding its result. The action will be invoked as many times as
-- the length of the smallest vector.
--
-- @since 0.5.0
szipWith6M_
  :: forall ra rb rc rd re rf a b c d e f g m
   . ( S.Stream ra Ix1 a
     , S.Stream rb Ix1 b
     , S.Stream rc Ix1 c
     , S.Stream rd Ix1 d
     , S.Stream re Ix1 e
     , S.Stream rf Ix1 f
     , Monad m
     )
  => (a -> b -> c -> d -> e -> f -> m g)
  -> Vector ra a
  -> Vector rb b
  -> Vector rc c
  -> Vector rd d
  -> Vector re e
  -> Vector rf f
  -> m ()
szipWith6M_ :: forall ra rb rc rd re rf a b c d e f g (m :: * -> *).
(Stream ra Int a, Stream rb Int b, Stream rc Int c,
 Stream rd Int d, Stream re Int e, Stream rf Int f, Monad m) =>
(a -> b -> c -> d -> e -> f -> m g)
-> Vector ra a
-> Vector rb b
-> Vector rc c
-> Vector rd d
-> Vector re e
-> Vector rf f
-> m ()
szipWith6M_ a -> b -> c -> d -> e -> f -> m g
f Vector ra a
v1 Vector rb b
v2 Vector rc c
v3 Vector rd d
v4 Vector re e
v5 Vector rf f
v6 =
  forall (m :: * -> *) a b c d e f g.
Monad m =>
(a -> b -> c -> d -> e -> f -> m g)
-> Steps m a
-> Steps m b
-> Steps m c
-> Steps m d
-> Steps m e
-> Steps m f
-> m ()
S.zipWith6M_
    a -> b -> c -> d -> e -> f -> m g
f
    (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector ra a
v1)
    (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rb b
v2)
    (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rc c
v3)
    (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rd d
v4)
    (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector re e
v5)
    (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rf f
v6)
{-# INLINE szipWith6M_ #-}

-- | Same as `szipWithM_`, zip two vectors together, but with an index aware
-- monadic action. The action will be invoked as many times as the length of the
-- smallest vector.
--
-- ==== __Examples__
--
-- @since 0.5.0
sizipWithM_
  :: forall ra rb a b c m
   . (S.Stream ra Ix1 a, S.Stream rb Ix1 b, Monad m)
  => (Ix1 -> a -> b -> m c)
  -> Vector ra a
  -> Vector rb b
  -> m ()
sizipWithM_ :: forall ra rb a b c (m :: * -> *).
(Stream ra Int a, Stream rb Int b, Monad m) =>
(Int -> a -> b -> m c) -> Vector ra a -> Vector rb b -> m ()
sizipWithM_ Int -> a -> b -> m c
f Vector ra a
v1 Vector rb b
v2 = forall (m :: * -> *) a b c.
Monad m =>
(a -> b -> m c) -> Steps m a -> Steps m b -> m ()
S.zipWithM_ (forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Int -> a -> b -> m c
f) (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m (ix, e)
toStreamIxM Vector ra a
v1) (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rb b
v2)
{-# INLINE sizipWithM_ #-}

-- | Same as `szipWith3M_`, zip three vectors together, but with an index aware
-- monadic action. The action will be invoked as many times as the length of the
-- smallest vector.
--
-- @since 0.5.0
sizipWith3M_
  :: forall ra rb rc a b c d m
   . (S.Stream ra Ix1 a, S.Stream rb Ix1 b, S.Stream rc Ix1 c, Monad m)
  => (Ix1 -> a -> b -> c -> m d)
  -> Vector ra a
  -> Vector rb b
  -> Vector rc c
  -> m ()
sizipWith3M_ :: forall ra rb rc a b c d (m :: * -> *).
(Stream ra Int a, Stream rb Int b, Stream rc Int c, Monad m) =>
(Int -> a -> b -> c -> m d)
-> Vector ra a -> Vector rb b -> Vector rc c -> m ()
sizipWith3M_ Int -> a -> b -> c -> m d
f Vector ra a
v1 Vector rb b
v2 Vector rc c
v3 = forall (m :: * -> *) a b c d.
Monad m =>
(a -> b -> c -> m d) -> Steps m a -> Steps m b -> Steps m c -> m ()
S.zipWith3M_ (forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Int -> a -> b -> c -> m d
f) (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m (ix, e)
toStreamIxM Vector ra a
v1) (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rb b
v2) (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rc c
v3)
{-# INLINE sizipWith3M_ #-}

-- | Same as `szipWith4M_`, zip four vectors together, but with an index aware
-- monadic action. The action will be invoked as many times as the length of the
-- smallest vector.
--
-- @since 0.5.0
sizipWith4M_
  :: forall ra rb rc rd a b c d e m
   . (S.Stream ra Ix1 a, S.Stream rb Ix1 b, S.Stream rc Ix1 c, S.Stream rd Ix1 d, Monad m)
  => (Ix1 -> a -> b -> c -> d -> m e)
  -> Vector ra a
  -> Vector rb b
  -> Vector rc c
  -> Vector rd d
  -> m ()
sizipWith4M_ :: forall ra rb rc rd a b c d e (m :: * -> *).
(Stream ra Int a, Stream rb Int b, Stream rc Int c,
 Stream rd Int d, Monad m) =>
(Int -> a -> b -> c -> d -> m e)
-> Vector ra a -> Vector rb b -> Vector rc c -> Vector rd d -> m ()
sizipWith4M_ Int -> a -> b -> c -> d -> m e
f Vector ra a
v1 Vector rb b
v2 Vector rc c
v3 Vector rd d
v4 =
  forall (m :: * -> *) a b c d e.
Monad m =>
(a -> b -> c -> d -> m e)
-> Steps m a -> Steps m b -> Steps m c -> Steps m d -> m ()
S.zipWith4M_ (forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Int -> a -> b -> c -> d -> m e
f) (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m (ix, e)
toStreamIxM Vector ra a
v1) (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rb b
v2) (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rc c
v3) (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rd d
v4)
{-# INLINE sizipWith4M_ #-}

-- | Same as `szipWith5M_`, zip five vectors together, but with an index aware
-- monadic action. The action will be invoked as many times as the length of the
-- smallest vector.
--
-- @since 0.5.0
sizipWith5M_
  :: forall ra rb rc rd re a b c d e f m
   . ( S.Stream ra Ix1 a
     , S.Stream rb Ix1 b
     , S.Stream rc Ix1 c
     , S.Stream rd Ix1 d
     , S.Stream re Ix1 e
     , Monad m
     )
  => (Ix1 -> a -> b -> c -> d -> e -> m f)
  -> Vector ra a
  -> Vector rb b
  -> Vector rc c
  -> Vector rd d
  -> Vector re e
  -> m ()
sizipWith5M_ :: forall ra rb rc rd re a b c d e f (m :: * -> *).
(Stream ra Int a, Stream rb Int b, Stream rc Int c,
 Stream rd Int d, Stream re Int e, Monad m) =>
(Int -> a -> b -> c -> d -> e -> m f)
-> Vector ra a
-> Vector rb b
-> Vector rc c
-> Vector rd d
-> Vector re e
-> m ()
sizipWith5M_ Int -> a -> b -> c -> d -> e -> m f
f Vector ra a
v1 Vector rb b
v2 Vector rc c
v3 Vector rd d
v4 Vector re e
v5 =
  forall (m :: * -> *) a b c d e f.
Monad m =>
(a -> b -> c -> d -> e -> m f)
-> Steps m a
-> Steps m b
-> Steps m c
-> Steps m d
-> Steps m e
-> m ()
S.zipWith5M_
    (forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Int -> a -> b -> c -> d -> e -> m f
f)
    (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m (ix, e)
toStreamIxM Vector ra a
v1)
    (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rb b
v2)
    (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rc c
v3)
    (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rd d
v4)
    (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector re e
v5)
{-# INLINE sizipWith5M_ #-}

-- | Same as `szipWith6M_`, zip six vectors together, but with an index aware
-- monadic action. The action will be invoked as many times as the length of the
-- smallest vector.
--
-- @since 0.5.0
sizipWith6M_
  :: forall ra rb rc rd re rf a b c d e f g m
   . ( S.Stream ra Ix1 a
     , S.Stream rb Ix1 b
     , S.Stream rc Ix1 c
     , S.Stream rd Ix1 d
     , S.Stream re Ix1 e
     , S.Stream rf Ix1 f
     , Monad m
     )
  => (Ix1 -> a -> b -> c -> d -> e -> f -> m g)
  -> Vector ra a
  -> Vector rb b
  -> Vector rc c
  -> Vector rd d
  -> Vector re e
  -> Vector rf f
  -> m ()
sizipWith6M_ :: forall ra rb rc rd re rf a b c d e f g (m :: * -> *).
(Stream ra Int a, Stream rb Int b, Stream rc Int c,
 Stream rd Int d, Stream re Int e, Stream rf Int f, Monad m) =>
(Int -> a -> b -> c -> d -> e -> f -> m g)
-> Vector ra a
-> Vector rb b
-> Vector rc c
-> Vector rd d
-> Vector re e
-> Vector rf f
-> m ()
sizipWith6M_ Int -> a -> b -> c -> d -> e -> f -> m g
f Vector ra a
v1 Vector rb b
v2 Vector rc c
v3 Vector rd d
v4 Vector re e
v5 Vector rf f
v6 =
  forall (m :: * -> *) a b c d e f g.
Monad m =>
(a -> b -> c -> d -> e -> f -> m g)
-> Steps m a
-> Steps m b
-> Steps m c
-> Steps m d
-> Steps m e
-> Steps m f
-> m ()
S.zipWith6M_
    (forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Int -> a -> b -> c -> d -> e -> f -> m g
f)
    (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m (ix, e)
toStreamIxM Vector ra a
v1)
    (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rb b
v2)
    (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rc c
v3)
    (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rd d
v4)
    (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector re e
v5)
    (forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rf f
v6)
{-# INLINE sizipWith6M_ #-}

-- | Streaming fold over an array in a row-major fashion with a left biased
-- function and a strict accumulator.
--
-- ==== __Examples__
--
-- @since 0.5.0
sfoldl
  :: forall r ix e a
   . Stream r ix e
  => (a -> e -> a)
  -> a
  -> Array r ix e
  -> a
sfoldl :: forall r ix e a.
Stream r ix e =>
(a -> e -> a) -> a -> Array r ix e -> a
sfoldl a -> e -> a
f a
acc = forall a. Id a -> a
S.unId forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) b a.
Monad m =>
(b -> a -> b) -> b -> Steps m a -> m b
S.foldl a -> e -> a
f a
acc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
toStream
{-# INLINE sfoldl #-}

-- |
--
-- ==== __Examples__
--
-- @since 0.5.0
sfoldlM
  :: forall r ix e a m
   . (Stream r ix e, Monad m)
  => (a -> e -> m a)
  -> a
  -> Array r ix e
  -> m a
sfoldlM :: forall r ix e a (m :: * -> *).
(Stream r ix e, Monad m) =>
(a -> e -> m a) -> a -> Array r ix e -> m a
sfoldlM a -> e -> m a
f a
acc = forall (m :: * -> *) a b.
Monad m =>
(a -> b -> m a) -> a -> Steps m b -> m a
S.foldlM a -> e -> m a
f a
acc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) e. Monad m => Steps Id e -> Steps m e
S.transStepsId forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
toStream
{-# INLINE sfoldlM #-}

-- |
--
-- ==== __Examples__
--
-- @since 0.5.0
sfoldlM_
  :: forall r ix e a m
   . (Stream r ix e, Monad m)
  => (a -> e -> m a)
  -> a
  -> Array r ix e
  -> m ()
sfoldlM_ :: forall r ix e a (m :: * -> *).
(Stream r ix e, Monad m) =>
(a -> e -> m a) -> a -> Array r ix e -> m ()
sfoldlM_ a -> e -> m a
f a
acc = forall (f :: * -> *) a. Functor f => f a -> f ()
void forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r ix e a (m :: * -> *).
(Stream r ix e, Monad m) =>
(a -> e -> m a) -> a -> Array r ix e -> m a
sfoldlM a -> e -> m a
f a
acc
{-# INLINE sfoldlM_ #-}

-- |
--
-- ==== __Examples__
--
-- @since 0.5.0
sfoldl1'
  :: forall r ix e
   . (HasCallStack, Stream r ix e)
  => (e -> e -> e)
  -> Array r ix e
  -> e
sfoldl1' :: forall r ix e.
(HasCallStack, Stream r ix e) =>
(e -> e -> e) -> Array r ix e -> e
sfoldl1' e -> e -> e
f = forall a. HasCallStack => Either SomeException a -> a
throwEither forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r ix e (m :: * -> *).
(Stream r ix e, MonadThrow m) =>
(e -> e -> m e) -> Array r ix e -> m e
sfoldl1M (\e
e -> forall (f :: * -> *) a. Applicative f => a -> f a
pure forall b c a. (b -> c) -> (a -> b) -> a -> c
. e -> e -> e
f e
e)
{-# INLINE sfoldl1' #-}

-- |
--
-- ==== __Examples__
--
-- @since 0.5.0
sfoldl1M
  :: forall r ix e m
   . (Stream r ix e, MonadThrow m)
  => (e -> e -> m e)
  -> Array r ix e
  -> m e
sfoldl1M :: forall r ix e (m :: * -> *).
(Stream r ix e, MonadThrow m) =>
(e -> e -> m e) -> Array r ix e -> m e
sfoldl1M e -> e -> m e
f Array r ix e
arr = do
  let str :: Steps m e
str = forall (m :: * -> *) e. Monad m => Steps Id e -> Steps m e
S.transStepsId forall a b. (a -> b) -> a -> b
$ forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
toStream Array r ix e
arr
  Bool
isNullStream <- forall (m :: * -> *) a. Monad m => Steps m a -> m Bool
S.null Steps m e
str
  forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
isNullStream forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwM forall a b. (a -> b) -> a -> b
$ forall ix. Index ix => Sz ix -> SizeException
SizeEmptyException (forall r ix e. Shape r ix => Array r ix e -> Sz ix
outerSize Array r ix e
arr)
  forall (m :: * -> *) a.
Monad m =>
(a -> a -> m a) -> Steps m a -> m a
S.foldl1M e -> e -> m e
f Steps m e
str
{-# INLINE sfoldl1M #-}

-- |
--
-- ==== __Examples__
--
-- @since 0.5.0
sfoldl1M_
  :: forall r ix e m
   . (Stream r ix e, MonadThrow m)
  => (e -> e -> m e)
  -> Array r ix e
  -> m ()
sfoldl1M_ :: forall r ix e (m :: * -> *).
(Stream r ix e, MonadThrow m) =>
(e -> e -> m e) -> Array r ix e -> m ()
sfoldl1M_ e -> e -> m e
f = forall (f :: * -> *) a. Functor f => f a -> f ()
void forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r ix e (m :: * -> *).
(Stream r ix e, MonadThrow m) =>
(e -> e -> m e) -> Array r ix e -> m e
sfoldl1M e -> e -> m e
f
{-# INLINE sfoldl1M_ #-}

-- |
--
-- ==== __Examples__
--
-- @since 0.5.0
sifoldl
  :: forall r ix e a
   . Stream r ix e
  => (a -> ix -> e -> a)
  -> a
  -> Array r ix e
  -> a
sifoldl :: forall r ix e a.
Stream r ix e =>
(a -> ix -> e -> a) -> a -> Array r ix e -> a
sifoldl a -> ix -> e -> a
f a
acc = forall a. Id a -> a
S.unId forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) b a.
Monad m =>
(b -> a -> b) -> b -> Steps m a -> m b
S.foldl (\a
a (ix
ix, e
e) -> a -> ix -> e -> a
f a
a ix
ix e
e) a
acc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r ix e. Stream r ix e => Array r ix e -> Steps Id (ix, e)
toStreamIx
{-# INLINE sifoldl #-}

-- |
--
-- ==== __Examples__
--
-- @since 0.5.0
sifoldlM
  :: forall r ix e a m
   . (Stream r ix e, Monad m)
  => (a -> ix -> e -> m a)
  -> a
  -> Array r ix e
  -> m a
sifoldlM :: forall r ix e a (m :: * -> *).
(Stream r ix e, Monad m) =>
(a -> ix -> e -> m a) -> a -> Array r ix e -> m a
sifoldlM a -> ix -> e -> m a
f a
acc = forall (m :: * -> *) a b.
Monad m =>
(a -> b -> m a) -> a -> Steps m b -> m a
S.foldlM (\a
a (ix
ix, e
e) -> a -> ix -> e -> m a
f a
a ix
ix e
e) a
acc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) e. Monad m => Steps Id e -> Steps m e
S.transStepsId forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r ix e. Stream r ix e => Array r ix e -> Steps Id (ix, e)
toStreamIx
{-# INLINE sifoldlM #-}

-- |
--
-- ==== __Examples__
--
-- @since 0.5.0
sifoldlM_
  :: forall r ix e a m
   . (Stream r ix e, Monad m)
  => (a -> ix -> e -> m a)
  -> a
  -> Array r ix e
  -> m ()
sifoldlM_ :: forall r ix e a (m :: * -> *).
(Stream r ix e, Monad m) =>
(a -> ix -> e -> m a) -> a -> Array r ix e -> m ()
sifoldlM_ a -> ix -> e -> m a
f a
acc = forall (f :: * -> *) a. Functor f => f a -> f ()
void forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r ix e a (m :: * -> *).
(Stream r ix e, Monad m) =>
(a -> ix -> e -> m a) -> a -> Array r ix e -> m a
sifoldlM a -> ix -> e -> m a
f a
acc
{-# INLINE sifoldlM_ #-}

-- |
--
-- ==== __Examples__
--
-- @since 0.5.0
sor
  :: forall r ix
   . Stream r ix Bool
  => Array r ix Bool
  -> Bool
sor :: forall r ix. Stream r ix Bool => Array r ix Bool -> Bool
sor = forall a. Id a -> a
S.unId forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *). Monad m => Steps m Bool -> m Bool
S.or forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
toStream
{-# INLINE sor #-}

-- |
--
-- ==== __Examples__
--
-- @since 0.5.0
sand :: forall r ix. Stream r ix Bool => Array r ix Bool -> Bool
sand :: forall r ix. Stream r ix Bool => Array r ix Bool -> Bool
sand = forall a. Id a -> a
S.unId forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *). Monad m => Steps m Bool -> m Bool
S.and forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
toStream
{-# INLINE sand #-}

-- |
--
-- ==== __Examples__
--
-- @since 0.5.0
sany :: forall r ix e. Stream r ix e => (e -> Bool) -> Array r ix e -> Bool
sany :: forall r ix e. Stream r ix e => (e -> Bool) -> Array r ix e -> Bool
sany e -> Bool
f = forall a. Id a -> a
S.unId forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *). Monad m => Steps m Bool -> m Bool
S.or forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) e a.
Monad m =>
(e -> a) -> Steps m e -> Steps m a
S.map e -> Bool
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
toStream
{-# INLINE sany #-}

-- |
--
-- ==== __Examples__
--
-- @since 0.5.0
sall :: forall r ix e. Stream r ix e => (e -> Bool) -> Array r ix e -> Bool
sall :: forall r ix e. Stream r ix e => (e -> Bool) -> Array r ix e -> Bool
sall e -> Bool
f = forall a. Id a -> a
S.unId forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *). Monad m => Steps m Bool -> m Bool
S.and forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) e a.
Monad m =>
(e -> a) -> Steps m e -> Steps m a
S.map e -> Bool
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
toStream
{-# INLINE sall #-}

-- | Add all elements of the array together
--
-- /Related/: `sum`.
--
-- ==== __Examples__
--
-- >>> import Data.Massiv.Vector as V
-- >>> V.ssum $ V.sfromList [10, 3, 70, 5 :: Int]
-- 88
--
-- @since 0.5.0
ssum :: forall r ix e. (Num e, Stream r ix e) => Array r ix e -> e
ssum :: forall r ix e. (Num e, Stream r ix e) => Array r ix e -> e
ssum = forall r ix e a.
Stream r ix e =>
(a -> e -> a) -> a -> Array r ix e -> a
sfoldl forall a. Num a => a -> a -> a
(+) e
0
{-# INLINE ssum #-}

-- | Multiply all elements of the array together
--
-- /Related/: `product`.
--
-- ==== __Examples__
--
-- >>> import Data.Massiv.Vector as V
-- >>> V.sproduct $ V.sfromList [10, 3, 70, 5 :: Int]
-- 10500
--
-- @since 0.5.0
sproduct :: forall r ix e. (Num e, Stream r ix e) => Array r ix e -> e
sproduct :: forall r ix e. (Num e, Stream r ix e) => Array r ix e -> e
sproduct = forall r ix e a.
Stream r ix e =>
(a -> e -> a) -> a -> Array r ix e -> a
sfoldl forall a. Num a => a -> a -> a
(*) e
1
{-# INLINE sproduct #-}

-- | /O(n)/ - Find the largest value in the array. Throws an error on empty.
--
-- /Related/: `smaximumM`, `maximum`, `maximumM`.
--
-- ==== __Examples__
--
-- >>> import Data.Massiv.Vector as V
-- >>> V.smaximum' $ V.sfromList [10, 3, 70, 5 :: Int]
-- 70
--
-- @since 0.5.0
smaximum' :: forall r ix e. (HasCallStack, Ord e, Stream r ix e) => Array r ix e -> e
smaximum' :: forall r ix e.
(HasCallStack, Ord e, Stream r ix e) =>
Array r ix e -> e
smaximum' = forall r ix e.
(HasCallStack, Stream r ix e) =>
(e -> e -> e) -> Array r ix e -> e
sfoldl1' forall a. Ord a => a -> a -> a
max
{-# INLINE smaximum' #-}

-- | /O(n)/ - Find the largest value in the array.
--
-- /Related/: `smaximum`, `maximum`, `maximumM`.
--
-- /__Throws Exceptions__/: `SizeEmptyException` when array is empty
--
-- ==== __Examples__
--
-- >>> import Data.Massiv.Vector as V
-- >>> V.smaximumM $ V.sfromList [10, 3, 70, 5 :: Int]
-- 70
-- >>> V.smaximumM (V.empty :: Vector D Int) :: Maybe Int
-- Nothing
--
-- @since 0.5.0
smaximumM :: forall r ix e m. (Ord e, Stream r ix e, MonadThrow m) => Array r ix e -> m e
smaximumM :: forall r ix e (m :: * -> *).
(Ord e, Stream r ix e, MonadThrow m) =>
Array r ix e -> m e
smaximumM = forall r ix e (m :: * -> *).
(Stream r ix e, MonadThrow m) =>
(e -> e -> m e) -> Array r ix e -> m e
sfoldl1M (\e
e e
acc -> forall (f :: * -> *) a. Applicative f => a -> f a
pure (forall a. Ord a => a -> a -> a
max e
e e
acc))
{-# INLINE smaximumM #-}

-- | /O(n)/ - Find the smallest value in the array. Throws an error on empty.
--
-- /Related/: `sminimumM`, `minimum`, `minimumM`.
--
-- ==== __Examples__
--
-- >>> import Data.Massiv.Vector as V
-- >>> V.sminimum' $ V.sfromList [10, 3, 70, 5 :: Int]
-- 3
--
-- @since 0.5.0
sminimum' :: forall r ix e. (HasCallStack, Ord e, Stream r ix e) => Array r ix e -> e
sminimum' :: forall r ix e.
(HasCallStack, Ord e, Stream r ix e) =>
Array r ix e -> e
sminimum' = forall r ix e.
(HasCallStack, Stream r ix e) =>
(e -> e -> e) -> Array r ix e -> e
sfoldl1' forall a. Ord a => a -> a -> a
min
{-# INLINE sminimum' #-}

-- | /O(n)/ - Find the smallest value in the array.
--
-- /Related/: 'sminimum'', `minimum`, `minimumM`.
--
-- /__Throws Exceptions__/: `SizeEmptyException` when array is empty
--
-- ==== __Examples__
--
-- >>> import Data.Massiv.Vector as V
-- >>> V.sminimumM $ V.sfromList [10, 3, 70, 5 :: Int]
-- 3
-- >>> V.sminimumM (V.empty :: Array D Ix2 Int) :: Maybe Int
-- Nothing
--
-- @since 0.5.0
sminimumM :: forall r ix e m. (Ord e, Stream r ix e, MonadThrow m) => Array r ix e -> m e
sminimumM :: forall r ix e (m :: * -> *).
(Ord e, Stream r ix e, MonadThrow m) =>
Array r ix e -> m e
sminimumM = forall r ix e (m :: * -> *).
(Stream r ix e, MonadThrow m) =>
(e -> e -> m e) -> Array r ix e -> m e
sfoldl1M (\e
e e
acc -> forall (f :: * -> *) a. Applicative f => a -> f a
pure (forall a. Ord a => a -> a -> a
min e
e e
acc))
{-# INLINE sminimumM #-}

-- | /O(n)/ - left scan with strict accumulator. First element is the value of the
-- accumulator. Last element is not included.
--
-- ==== __Examples__
--
-- >>> import Data.Massiv.Vector
-- >>> sprescanl min 6 $ sfromList [10, 5, 70, 3 :: Int]
-- Array DS Seq (Sz1 4)
--   [ 6, 6, 5, 5 ]
-- >>> sprescanl (+) 0 $ sfromList [10, 5, 70, 3 :: Int]
-- Array DS Seq (Sz1 4)
--   [ 0, 10, 15, 85 ]
--
-- @since 1.0.3
sprescanl :: Stream r ix e => (a -> e -> a) -> a -> Array r ix e -> Vector DS a
sprescanl :: forall r ix e a.
Stream r ix e =>
(a -> e -> a) -> a -> Array r ix e -> Vector DS a
sprescanl a -> e -> a
f a
acc = forall e. Steps Id e -> Vector DS e
DSArray forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a b.
Monad m =>
(a -> b -> m a) -> a -> Steps m b -> Steps m a
S.prescanlM (\a
a e
b -> forall (f :: * -> *) a. Applicative f => a -> f a
pure (a -> e -> a
f a
a e
b)) a
acc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
toStream
{-# INLINE sprescanl #-}

-- | /O(n)/ - left scan with strict accumulator. First element is the result of applying
-- the supplied function.
--
-- ==== __Examples__
--
-- >>> import Data.Massiv.Vector
-- >>> spostscanl min 6 $ sfromList [10, 5, 70, 3 :: Int]
-- Array DS Seq (Sz1 4)
--   [ 6, 5, 5, 3 ]
-- >>> spostscanl (+) 0 $ sfromList [10, 5, 70, 3 :: Int]
-- Array DS Seq (Sz1 4)
--   [ 10, 15, 85, 88 ]
--
-- @since 1.0.3
spostscanl :: Stream r ix e => (a -> e -> a) -> a -> Array r ix e -> Vector DS a
spostscanl :: forall r ix e a.
Stream r ix e =>
(a -> e -> a) -> a -> Array r ix e -> Vector DS a
spostscanl a -> e -> a
f a
acc = forall e. Steps Id e -> Vector DS e
DSArray forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a b.
Monad m =>
(a -> b -> m a) -> a -> Steps m b -> Steps m a
S.postscanlM (\a
a e
b -> forall (f :: * -> *) a. Applicative f => a -> f a
pure (a -> e -> a
f a
a e
b)) a
acc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
toStream
{-# INLINE spostscanl #-}

-- | /O(n)/ - Just like `spostscanl` except it is possible to produce a vector with an
-- element type that differes from accumulator type.
--
-- ==== __Examples__
--
-- >>> import Data.Massiv.Vector
-- >>> spostscanlAcc (\x y -> if x < y then (True, x) else (False, y)) 6 $ sfromList [10, 5, 70, 3 :: Int]
-- Array DS Seq (Sz1 4)
--   [ True, False, True, False ]
--
-- @since 1.0.3
spostscanlAcc :: Stream r ix e => (c -> e -> (a, c)) -> c -> Array r ix e -> Vector DS a
spostscanlAcc :: forall r ix e c a.
Stream r ix e =>
(c -> e -> (a, c)) -> c -> Array r ix e -> Vector DS a
spostscanlAcc c -> e -> (a, c)
f c
acc = forall e. Steps Id e -> Vector DS e
DSArray forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) c b a.
Monad m =>
(c -> b -> m (a, c)) -> c -> Steps m b -> Steps m a
S.postscanlAccM (\c
a e
b -> forall (f :: * -> *) a. Applicative f => a -> f a
pure (c -> e -> (a, c)
f c
a e
b)) c
acc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
toStream
{-# INLINE spostscanlAcc #-}


-- | /O(n)/ - left scan with strict accumulator. First element is the value of the accumulator.
--
-- ==== __Examples__
--
-- >>> import Data.Massiv.Vector
-- >>> sscanl min 6 $ sfromList [10, 5, 70, 3 :: Int]
-- Array DS Seq (Sz1 5)
--   [ 6, 6, 5, 5, 3 ]
-- >>> sscanl (+) 0 $ sfromList [10, 5, 70, 3 :: Int]
-- Array DS Seq (Sz1 5)
--   [ 0, 10, 15, 85, 88 ]
--
-- @since 1.0.3
sscanl :: Stream r ix e => (a -> e -> a) -> a -> Array r ix e -> Vector DS a
sscanl :: forall r ix e a.
Stream r ix e =>
(a -> e -> a) -> a -> Array r ix e -> Vector DS a
sscanl a -> e -> a
f a
acc = forall e. Steps Id e -> Vector DS e
DSArray forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a b.
Monad m =>
(a -> b -> m a) -> a -> Steps m b -> Steps m a
S.scanlM (\a
a e
b -> forall (f :: * -> *) a. Applicative f => a -> f a
pure (a -> e -> a
f a
a e
b)) a
acc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
toStream
{-# INLINE sscanl #-}

-- | /O(n)/ - left scan with strict accumulator and no initial value for the accumulator.
--
-- ==== __Examples__
--
-- >>> import Data.Massiv.Vector
-- >>> sscanl1 min $ sfromList [10, 5, 70, 3 :: Int]
-- Array DS Seq (Sz1 4)
--   [ 10, 5, 5, 3 ]
-- >>> sscanl1 (+) $ sfromList [10, 5, 70, 3 :: Int]
-- Array DS Seq (Sz1 4)
--   [ 10, 15, 85, 88 ]
-- >>> sscanl1 (+) $ sfromList ([] :: [Int])
-- Array DS Seq (Sz1 0)
--   [  ]
--
-- @since 1.0.3
sscanl1 :: Stream r ix e => (e -> e -> e) -> Array r ix e -> Vector DS e
sscanl1 :: forall r ix e.
Stream r ix e =>
(e -> e -> e) -> Array r ix e -> Vector DS e
sscanl1 e -> e -> e
f = forall e. Steps Id e -> Vector DS e
DSArray forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a.
Monad m =>
(a -> a -> m a) -> Steps m a -> Steps m a
S.scanl1M (\e
a e
b -> forall (f :: * -> *) a. Applicative f => a -> f a
pure (e -> e -> e
f e
a e
b)) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
toStream
{-# INLINE sscanl1 #-}