{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE FlexibleContexts #-}
{-# OPTIONS_GHC -fno-warn-duplicate-exports #-}
-- |
-- Module      : Data.Massiv.Vector
-- Copyright   : (c) Alexey Kuleshevich 2020-2021
-- License     : BSD3
-- Maintainer  : Alexey Kuleshevich <lehins@yandex.ru>
-- Stability   : experimental
-- Portability : non-portable
--
module Data.Massiv.Vector
  ( Vector
  , MVector
  -- * Accessors
  -- *** Size
  , slength
  , maxSize
  , size
  , snull
  -- *** 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
  -- -- ** Mutable 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
  -- -- ** Prefix sums
  -- , prescanl
  -- , prescanl'
  -- , postscanl
  -- , postscanl'
  -- , scanl
  -- , scanl'
  -- , scanl1
  -- , scanl1'
  -- , prescanr
  -- , prescanr'
  -- , postscanr
  -- , postscanr'
  -- , scanr
  -- , scanr'
  -- , scanr1
  -- , scanr1'
  -- * Conversions
  -- ** Lists
  , stoList
  , fromList
  , sfromList
  , sfromListN
  -- * Computation
  , compute
  , computeS
  , computeIO
  , computePrimM
  , computeAs
  , computeProxy
  , computeSource
  , computeWithStride
  , computeWithStrideAs
  , clone
  , convert
  , convertAs
  , convertProxy
  -- -- ** Other vector types
  -- , convert
  -- -- ** Mutable vectors
  -- , freeze
  -- , thaw
  -- , copy
  -- , unsafeFreeze
  -- , unsafeThaw
  -- , unsafeCopy
  -- * Deprecated
  , takeS
  , dropS
  , unfoldr
  , unfoldrN
  , filterS
  , ifilterS
  , filterM
  , ifilterM
  , mapMaybeS
  , imapMaybeS
  , mapMaybeM
  , imapMaybeM
  , catMaybesS
  , traverseS
  -- ** 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 (makeArrayR, 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, init, length, null, replicate, splitAt, tail, take, takeWhile, dropWhile)

-- ========= --
-- 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/: `maxSize`, `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 rarely 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 :: Stream r ix e => Array r ix e -> Maybe Sz1
slength :: Array r ix e -> Maybe Sz1
slength Array r ix e
v =
  case Steps Id e -> Size
forall (m :: * -> *) e. Steps m e -> Size
stepsSize (Array r ix e -> Steps Id e
forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
toStream Array r ix e
v) of
    Exact Int
sz -> Sz1 -> Maybe Sz1
forall a. a -> Maybe a
Just (Int -> Sz1
forall ix. ix -> Sz ix
SafeSz Int
sz)
    Size
_        -> Maybe Sz1
forall a. Maybe a
Nothing
{-# INLINE slength #-}

-- | /O(1)/ - Check whether a `Stream` array is empty or not. It only looks at the exact size
-- (i.e. `slength`), if it is available, otherwise checks if there is at least one element
-- in a stream.
--
-- /Related/: `isEmpty`, `isNotEmpty`
--
-- ==== __Examples__
--
-- >>> snull sempty
-- True
-- >>> snull (empty :: Array D Ix5 Int)
-- True
-- >>> snull $ ssingleton "A Vector with a single String element"
-- False
-- >>> snull $ sfromList []
-- True
-- >>> snull $ sfromList [1 :: Int ..]
-- False
--
-- /__Similar__/:
--
-- [@Data.Foldable.`Data.Foldable.null`@] List fusion is also broken with a check for
-- emptiness, unless there are no other consumers of the list.
--
-- [@Data.Vector.Generic.`Data.Vector.Generic.null`@] Same as with
-- `Data.Vector.Generic.length`, unless it is the only operation applied to the vector it
-- will break fusion and will result in the vector being fully materialized in memory.
--
-- @since 0.5.0
snull :: Load r ix e => Array r ix e -> Bool
snull :: Array r ix e -> Bool
snull = Array r ix e -> Bool
forall r ix e. Load r ix e => Array r ix e -> Bool
isEmpty
{-# INLINE snull #-}

--------------
-- 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
-- >>> head' (Ix1 10 ..: 10)
-- *** Exception: SizeEmptyException: (Sz1 0) corresponds to an empty array
--
-- /__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' :: Source r Ix1 e => Vector r e -> e
head' :: Vector r e -> e
head' = (SomeException -> e) -> (e -> e) -> Either SomeException e -> e
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either SomeException -> e
forall a e. Exception e => e -> a
throw e -> e
forall a. a -> a
id (Either SomeException e -> e)
-> (Vector r e -> Either SomeException e) -> Vector r e -> e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector r e -> Either SomeException e
forall r e (m :: * -> *).
(Source r Int 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 :: (Source r Ix1 e, MonadThrow m) => Vector r e -> m e
headM :: Vector r e -> m e
headM Vector r e
v
  | Vector r e -> Bool
forall r ix e. Load r ix e => Array r ix e -> Bool
isEmpty Vector r e
v = SizeException -> m e
forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwM (SizeException -> m e) -> SizeException -> m e
forall a b. (a -> b) -> a -> b
$ Sz1 -> SizeException
forall ix. Index ix => Sz ix -> SizeException
SizeEmptyException (Vector r e -> Sz1
forall r ix e. Load r ix e => Array r ix e -> Sz ix
size Vector r e
v)
  | Bool
otherwise = e -> m e
forall (f :: * -> *) a. Applicative f => a -> f a
pure (e -> m e) -> e -> m e
forall a b. (a -> b) -> a -> b
$ Vector r e -> Int -> e
forall r ix e. Source r ix e => 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
-- >>> x = shead' $ sunfoldr (\_ -> Nothing) (0 :: Int)
-- >>> print x
-- *** Exception: SizeEmptyException: (Sz1 0) corresponds to an empty array
--
-- @since 0.5.0
shead' :: Stream r Ix1 e => Vector r e -> e
shead' :: Vector r e -> e
shead' = (SomeException -> e) -> (e -> e) -> Either SomeException e -> e
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either SomeException -> e
forall a e. Exception e => e -> a
throw e -> e
forall a. a -> a
id (Either SomeException e -> e)
-> (Vector r e -> Either SomeException e) -> Vector r e -> e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector r e -> Either SomeException e
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 :: (Stream r Ix1 e, MonadThrow m) => Vector r e -> m e
sheadM :: Vector r e -> m e
sheadM Vector r e
v =
  case Id (Maybe e) -> Maybe e
forall a. Id a -> a
S.unId (Steps Id e -> Id (Maybe e)
forall (m :: * -> *) a. Monad m => Steps m a -> m (Maybe a)
S.headMaybe (Vector r e -> Steps Id e
forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
toStream Vector r e
v)) of
    Maybe e
Nothing -> SizeException -> m e
forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwM (SizeException -> m e) -> SizeException -> m e
forall a b. (a -> b) -> a -> b
$ Sz1 -> SizeException
forall ix. Index ix => Sz ix -> SizeException
SizeEmptyException (Vector r e -> Sz1
forall r ix e. Load r ix e => Array r ix e -> Sz ix
size Vector r e
v)
    Just e
e  -> e -> m 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 :: (MonadThrow m, Source r Ix1 e) => Vector r e -> m (e, Vector r e)
unconsM :: Vector r e -> m (e, Vector r e)
unconsM Vector r e
arr
  | Int
0 Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Sz1 -> Int
forall ix. Index ix => Sz ix -> Int
totalElem Sz1
sz = SizeException -> m (e, Vector r e)
forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwM (SizeException -> m (e, Vector r e))
-> SizeException -> m (e, Vector r e)
forall a b. (a -> b) -> a -> b
$ Sz1 -> SizeException
forall ix. Index ix => Sz ix -> SizeException
SizeEmptyException Sz1
sz
  | Bool
otherwise = (e, Vector r e) -> m (e, Vector r e)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Vector r e -> Int -> e
forall r ix e. Source r ix e => Array r ix e -> Int -> e
unsafeLinearIndex Vector r e
arr Int
0, Int -> Sz1 -> Vector r e -> Vector r e
forall r ix e.
Source r ix e =>
Int -> Sz1 -> Array r ix e -> Array r Int e
unsafeLinearSlice Int
1 (Int -> Sz1
forall ix. ix -> Sz ix
SafeSz (Sz1 -> Int
forall ix. Sz ix -> ix
unSz Sz1
sz Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)) Vector r e
arr)
  where
    !sz :: Sz1
sz = Vector r e -> Sz1
forall r ix e. Load r ix e => 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 :: (MonadThrow m, Source r Ix1 e) => Vector r e -> m (Vector r e, e)
unsnocM :: Vector r e -> m (Vector r e, e)
unsnocM Vector r e
arr
  | Int
0 Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Sz1 -> Int
forall ix. Index ix => Sz ix -> Int
totalElem Sz1
sz = SizeException -> m (Vector r e, e)
forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwM (SizeException -> m (Vector r e, e))
-> SizeException -> m (Vector r e, e)
forall a b. (a -> b) -> a -> b
$ Sz1 -> SizeException
forall ix. Index ix => Sz ix -> SizeException
SizeEmptyException Sz1
sz
  | Bool
otherwise = (Vector r e, e) -> m (Vector r e, e)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int -> Sz1 -> Vector r e -> Vector r e
forall r ix e.
Source r ix e =>
Int -> Sz1 -> Array r ix e -> Array r Int e
unsafeLinearSlice Int
0 (Int -> Sz1
forall ix. ix -> Sz ix
SafeSz Int
k) Vector r e
arr, Vector r e -> Int -> e
forall r ix e. Source r ix e => Array r ix e -> Int -> e
unsafeLinearIndex Vector r e
arr Int
k)
  where
    !sz :: Sz1
sz = Vector r e -> Sz1
forall r ix e. Load r ix e => Array r ix e -> Sz ix
size Vector r e
arr
    !k :: Int
k = Sz1 -> Int
forall ix. Sz ix -> ix
unSz Sz1
sz Int -> Int -> Int
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
-- >>> last' (fromList Seq [] :: Array P Ix1 Int)
-- *** Exception: SizeEmptyException: (Sz1 0) corresponds to an empty array
--
-- /__Similar__/:
--
-- [@Data.List.`Data.List.last`@] Also partial, but it has /O(n)/ complixity. 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' :: Source r Ix1 e => Vector r e -> e
last' :: Vector r e -> e
last' = (SomeException -> e) -> (e -> e) -> Either SomeException e -> e
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either SomeException -> e
forall a e. Exception e => e -> a
throw e -> e
forall a. a -> a
id (Either SomeException e -> e)
-> (Vector r e -> Either SomeException e) -> Vector r e -> e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector r e -> Either SomeException e
forall r e (m :: * -> *).
(Source r Int 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 :: (Source r Ix1 e, MonadThrow m) => Vector r e -> m e
lastM :: Vector r e -> m e
lastM Vector r e
v
  | Int
k Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 = SizeException -> m e
forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwM (SizeException -> m e) -> SizeException -> m e
forall a b. (a -> b) -> a -> b
$ Sz1 -> SizeException
forall ix. Index ix => Sz ix -> SizeException
SizeEmptyException (Vector r e -> Sz1
forall r ix e. Load r ix e => Array r ix e -> Sz ix
size Vector r e
v)
  | Bool
otherwise = e -> m e
forall (f :: * -> *) a. Applicative f => a -> f a
pure (e -> m e) -> e -> m e
forall a b. (a -> b) -> a -> b
$ Vector r e -> Int -> e
forall r ix e. Source r ix e => Array r ix e -> Int -> e
unsafeLinearIndex Vector r e
v (Int
k Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
  where k :: Int
k = Sz1 -> Int
forall ix. Sz ix -> ix
unSz (Vector r e -> Sz1
forall r ix e. Load r ix e => 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 :: Source r Ix1 e => Ix1 -> Sz1 -> Vector r e -> Vector r e
slice :: Int -> Sz1 -> Vector r e -> Vector r e
slice !Int
i (Sz Int
k) Vector r e
v = Int -> Sz1 -> Vector r e -> Vector r e
forall r ix e.
Source r ix e =>
Int -> Sz1 -> Array r ix e -> Array r Int e
unsafeLinearSlice Int
i' Sz1
newSz Vector r e
v
  where
    !i' :: Int
i' = Int -> Int -> Int
forall a. Ord a => a -> a -> a
min Int
n (Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
0 Int
i)
    !newSz :: Sz1
newSz = Int -> Sz1
forall ix. ix -> Sz ix
SafeSz (Int -> Int -> Int
forall a. Ord a => a -> a -> a
min (Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
i') Int
k)
    Sz Int
n = Vector r e -> Sz1
forall r ix e. Load r ix e => 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' (-10) 5 (Ix1 0 ... 100)
-- Array D *** Exception: SizeSubregionException: (Sz1 101) is to small for -10 (Sz1 5)
-- >>> slice' 98 50 (Ix1 0 ... 100)
-- Array D *** Exception: SizeSubregionException: (Sz1 101) is to small for 98 (Sz1 50)
-- >>> slice' 9999999999998 50 (Ix1 0 ... 10000000000000)
-- Array D *** Exception: SizeSubregionException: (Sz1 10000000000001) is to small for 9999999999998 (Sz1 50)
-- >>> slice' 9999999999998 3 (Ix1 0 ... 10000000000000)
-- Array D Seq (Sz1 3)
--   [ 9999999999998, 9999999999999, 10000000000000 ]
--
-- @since 0.5.0
slice' :: Source r Ix1 e => Ix1 -> Sz1 -> Vector r e -> Vector r e
slice' :: Int -> Sz1 -> Vector r e -> Vector r e
slice' Int
i Sz1
k = (SomeException -> Vector r e)
-> (Vector r e -> Vector r e)
-> Either SomeException (Vector r e)
-> Vector r e
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either SomeException -> Vector r e
forall a e. Exception e => e -> a
throw Vector r e -> Vector r e
forall a. a -> a
id (Either SomeException (Vector r e) -> Vector r e)
-> (Vector r e -> Either SomeException (Vector r e))
-> Vector r e
-> Vector r e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Sz1 -> Vector r e -> Either SomeException (Vector r e)
forall r e (m :: * -> *).
(Source r Int 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__
--
--
-- @since 0.5.0
sliceM :: (Source r Ix1 e, MonadThrow m) => Ix1 -> Sz1 -> Vector r e -> m (Vector r e)
sliceM :: Int -> Sz1 -> Vector r e -> m (Vector r e)
sliceM Int
i newSz :: Sz1
newSz@(Sz Int
k) Vector r e
v
  | Int
i Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
0 Bool -> Bool -> Bool
&& Int
k Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
i = Vector r e -> m (Vector r e)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Vector r e -> m (Vector r e)) -> Vector r e -> m (Vector r e)
forall a b. (a -> b) -> a -> b
$ Int -> Sz1 -> Vector r e -> Vector r e
forall r ix e.
Source r ix e =>
Int -> Sz1 -> Array r ix e -> Array r Int e
unsafeLinearSlice Int
i Sz1
newSz Vector r e
v
  | Bool
otherwise = SizeException -> m (Vector r e)
forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwM (SizeException -> m (Vector r e))
-> SizeException -> m (Vector r e)
forall a b. (a -> b) -> a -> b
$ Sz1 -> Int -> Sz1 -> SizeException
forall ix. Index ix => Sz ix -> ix -> Sz ix -> SizeException
SizeSubregionException Sz1
sz Int
i Sz1
newSz
  where
    sz :: Sz1
sz@(Sz Int
n) = Vector r e -> Sz1
forall r ix e. Load r ix e => 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 :: Stream r Ix1 e => Ix1 -> Sz1 -> Vector r e -> Vector DS e
sslice :: Int -> Sz1 -> Vector r e -> Vector DS e
sslice !Int
i (Sz Int
k) = Steps Id e -> Vector DS e
forall e. Steps Id e -> Array DS Int e
fromSteps (Steps Id e -> Vector DS e)
-> (Vector r e -> Steps Id e) -> Vector r e -> Vector DS e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Int -> Steps Id e -> Steps Id e
forall (m :: * -> *) a.
Monad m =>
Int -> Int -> Steps m a -> Steps m a
S.slice Int
i Int
k (Steps Id e -> Steps Id e)
-> (Vector r e -> Steps Id e) -> Vector r e -> Steps Id e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector r e -> Steps Id e
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__
--
-- >>> init (0 ..: 10)
-- Array D Seq (Sz1 9)
--   [ 0, 1, 2, 3, 4, 5, 6, 7, 8 ]
-- >>> init (empty :: Array D Ix1 Int)
-- Array D Seq (Sz1 0)
--   [  ]
--
-- @since 0.5.0
init :: Source r Ix1 e => Vector r e -> Vector r e
init :: Vector r e -> Vector r e
init Vector r e
v = Int -> Sz1 -> Vector r e -> Vector r e
forall r ix e.
Source r ix e =>
Int -> Sz1 -> Array r ix e -> Array r Int e
unsafeLinearSlice Int
0 (Int -> Sz1
forall ix. Index ix => ix -> Sz ix
Sz (Sz1 -> Int
coerce (Vector r e -> Sz1
forall r ix e. Load r ix e => Array r ix e -> Sz ix
size Vector r e
v) Int -> Int -> Int
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 ]
-- >>> init' (empty :: Array D Ix1 Int)
-- Array D *** Exception: SizeEmptyException: (Sz1 0) corresponds to an empty array
--
-- @since 0.5.0
init' :: Source r Ix1 e => Vector r e -> Vector r e
init' :: Vector r e -> Vector r e
init' = (SomeException -> Vector r e)
-> (Vector r e -> Vector r e)
-> Either SomeException (Vector r e)
-> Vector r e
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either SomeException -> Vector r e
forall a e. Exception e => e -> a
throw Vector r e -> Vector r e
forall a. a -> a
id (Either SomeException (Vector r e) -> Vector r e)
-> (Vector r e -> Either SomeException (Vector r e))
-> Vector r e
-> Vector r e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector r e -> Either SomeException (Vector r e)
forall r e (m :: * -> *).
(Source r Int 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__
--
-- >>> initM (0 ..: 10)
-- Array D Seq (Sz1 9)
--   [ 0, 1, 2, 3, 4, 5, 6, 7, 8 ]
-- >>> maybe 0 sum $ initM (0 ..: 10)
-- 36
-- >>> maybe 0 sum $ initM (empty :: Array D Ix1 Int)
-- 0
--
-- @since 0.5.0
initM :: (Source r Ix1 e, MonadThrow m) => Vector r e -> m (Vector r e)
initM :: Vector r e -> m (Vector r e)
initM Vector r e
v = do
  Bool -> m () -> m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Vector r e -> Bool
forall r ix e. Load r ix e => Array r ix e -> Bool
isEmpty Vector r e
v) (m () -> m ()) -> m () -> m ()
forall a b. (a -> b) -> a -> b
$ SizeException -> m ()
forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwM (SizeException -> m ()) -> SizeException -> m ()
forall a b. (a -> b) -> a -> b
$ Sz1 -> SizeException
forall ix. Index ix => Sz ix -> SizeException
SizeEmptyException (Sz1 -> SizeException) -> Sz1 -> SizeException
forall a b. (a -> b) -> a -> b
$ Vector r e -> Sz1
forall r ix e. Load r ix e => Array r ix e -> Sz ix
size Vector r e
v
  Vector r e -> m (Vector r e)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Vector r e -> m (Vector r e)) -> Vector r e -> m (Vector r e)
forall a b. (a -> b) -> a -> b
$ Vector r e -> Vector r e
forall r e. Source r Int 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__
--
-- >>> 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 Seq (Sz1 0)
--   [  ]
--
-- @since 0.5.0
tail :: Source r Ix1 e => Vector r e -> Vector r e
tail :: Vector r e -> Vector r e
tail = Sz1 -> Vector r e -> Vector r e
forall r e. Source r Int e => Sz1 -> Vector r e -> Vector r e
drop Sz1
1
{-# 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' :: Source r Ix1 e => Vector r e -> Vector r e
tail' :: Vector r e -> Vector r e
tail' = (SomeException -> Vector r e)
-> (Vector r e -> Vector r e)
-> Either SomeException (Vector r e)
-> Vector r e
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either SomeException -> Vector r e
forall a e. Exception e => e -> a
throw Vector r e -> Vector r e
forall a. a -> a
id (Either SomeException (Vector r e) -> Vector r e)
-> (Vector r e -> Either SomeException (Vector r e))
-> Vector r e
-> Vector r e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector r e -> Either SomeException (Vector r e)
forall r e (m :: * -> *).
(Source r Int 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__
--
-- >>> tailM (0 ..: 10)
-- Array D Seq (Sz1 9)
--   [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
-- >>> maybe 0 sum $ tailM (0 ..: 10)
-- 45
-- >>> maybe 0 sum $ tailM (empty :: Array D Ix1 Int)
-- 0
--
-- @since 0.5.0
tailM :: (Source r Ix1 e, MonadThrow m) => Vector r e -> m (Vector r e)
tailM :: Vector r e -> m (Vector r e)
tailM Vector r e
v = do
  Bool -> m () -> m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Vector r e -> Bool
forall r ix e. Load r ix e => Array r ix e -> Bool
isEmpty Vector r e
v) (m () -> m ()) -> m () -> m ()
forall a b. (a -> b) -> a -> b
$ SizeException -> m ()
forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwM (SizeException -> m ()) -> SizeException -> m ()
forall a b. (a -> b) -> a -> b
$ Sz1 -> SizeException
forall ix. Index ix => Sz ix -> SizeException
SizeEmptyException (Sz1 -> SizeException) -> Sz1 -> SizeException
forall a b. (a -> b) -> a -> b
$ Vector r e -> Sz1
forall r ix e. Load r ix e => Array r ix e -> Sz ix
size Vector r e
v
  Vector r e -> m (Vector r e)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Vector r e -> m (Vector r e)) -> Vector r e -> m (Vector r e)
forall a b. (a -> b) -> a -> b
$ Vector r e -> Vector r e
forall r e. Source r Int e => Vector r e -> Vector r e
unsafeTail Vector r e
v
{-# INLINE tailM #-}



-- | /O(1)/ - Get the vector with the first @n@ elements. Never fails
--
-- ==== __Examples__
--
-- >>> take 5 (0 ..: 10)
-- Array D Seq (Sz1 5)
--   [ 0, 1, 2, 3, 4 ]
-- >>> take (-5) (0 ..: 10)
-- Array D Seq (Sz1 0)
--   [  ]
-- >>> 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 Ix1 e => Sz1 -> Vector r e -> Vector r e
take :: Sz1 -> Vector r e -> Vector r e
take Sz1
k = (Vector r e, Vector r e) -> Vector r e
forall a b. (a, b) -> a
fst ((Vector r e, Vector r e) -> Vector r e)
-> (Vector r e -> (Vector r e, Vector r e))
-> Vector r e
-> Vector r e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Sz1 -> Vector r e -> (Vector r e, Vector r e)
forall r e.
Source r Int 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 Ix1 e => (e -> Bool) -> Vector r e -> Vector r e
takeWhile :: (e -> Bool) -> Vector r e -> Vector r e
takeWhile e -> Bool
f Vector r e
v = Sz1 -> Vector r e -> Vector r e
forall r e. Source r Int e => Sz1 -> Vector r e -> Vector r e
take (Int -> Sz1
go Int
0) Vector r e
v
  where
    !k :: Int
k = Vector r e -> Int
forall r ix e. Load r ix e => Array r ix e -> Int
elemsCount Vector r e
v
    go :: Int -> Sz1
go !Int
i
      | Int
i Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
k Bool -> Bool -> Bool
&& e -> Bool
f (Vector r e -> Int -> e
forall r ix e. Source r ix e => Array r ix e -> Int -> e
unsafeLinearIndex Vector r e
v Int
i) = Int -> Sz1
go (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
      | Bool
otherwise = Int -> Sz1
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 ]
-- >>> take' 15 (0 ..: 10)
-- Array D *** Exception: SizeSubregionException: (Sz1 10) is to small for 0 (Sz1 15)
--
-- @since 0.5.0
take' :: Source r Ix1 e => Sz1 -> Vector r e -> Vector r e
take' :: Sz1 -> Vector r e -> Vector r e
take' Sz1
k = (SomeException -> Vector r e)
-> (Vector r e -> Vector r e)
-> Either SomeException (Vector r e)
-> Vector r e
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either SomeException -> Vector r e
forall a e. Exception e => e -> a
throw Vector r e -> Vector r e
forall a. a -> a
id (Either SomeException (Vector r e) -> Vector r e)
-> (Vector r e -> Either SomeException (Vector r e))
-> Vector r e
-> Vector r e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Sz1 -> Vector r e -> Either SomeException (Vector r e)
forall r e (m :: * -> *).
(Source r Int 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__
--
-- >>> takeM 5 (0 ..: 10)
-- Array D Seq (Sz1 5)
--   [ 0, 1, 2, 3, 4 ]
-- >>> maybe 0 sum $ takeM 5 (0 ..: 10)
-- 10
-- >>> maybe (-1) sum $ takeM 15 (0 ..: 10)
-- -1
--
-- @since 0.5.0
takeM :: (Source r Ix1 e, MonadThrow m) => Sz1 -> Vector r e -> m (Vector r e)
takeM :: Sz1 -> Vector r e -> m (Vector r e)
takeM Sz1
k Vector r e
v = do
  let sz :: Sz1
sz = Vector r e -> Sz1
forall r ix e. Load r ix e => Array r ix e -> Sz ix
size Vector r e
v
  Bool -> m () -> m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Sz1
k Sz1 -> Sz1 -> Bool
forall a. Ord a => a -> a -> Bool
> Sz1
sz) (m () -> m ()) -> m () -> m ()
forall a b. (a -> b) -> a -> b
$ SizeException -> m ()
forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwM (SizeException -> m ()) -> SizeException -> m ()
forall a b. (a -> b) -> a -> b
$ Sz1 -> Int -> Sz1 -> SizeException
forall ix. Index ix => Sz ix -> ix -> Sz ix -> SizeException
SizeSubregionException Sz1
sz Int
0 Sz1
k
  Vector r e -> m (Vector r e)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Vector r e -> m (Vector r e)) -> Vector r e -> m (Vector r e)
forall a b. (a -> b) -> a -> b
$ Sz1 -> Vector r e -> Vector r e
forall r e. Source r Int e => Sz1 -> Vector r e -> Vector r e
unsafeTake Sz1
k Vector r e
v
{-# INLINE takeM #-}

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

-- |
--
-- ==== __Examples__
--
-- @since 0.5.0
drop :: Source r Ix1 e => Sz1 -> Vector r e -> Vector r e
drop :: Sz1 -> Vector r e -> Vector r e
drop Sz1
k = (Vector r e, Vector r e) -> Vector r e
forall a b. (a, b) -> b
snd ((Vector r e, Vector r e) -> Vector r e)
-> (Vector r e -> (Vector r e, Vector r e))
-> Vector r e
-> Vector r e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Sz1 -> Vector r e -> (Vector r e, Vector r e)
forall r e.
Source r Int 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 :: Manifest r Ix1 e => (e -> Bool) -> Vector r e -> Vector r e
dropWhile :: (e -> Bool) -> Vector r e -> Vector r e
dropWhile e -> Bool
f Vector r e
v = Sz1 -> Vector r e -> Vector r e
forall r e. Source r Int e => Sz1 -> Vector r e -> Vector r e
drop (Int -> Sz1
go Int
0) Vector r e
v
  where
    !k :: Int
k = Vector r e -> Int
forall r ix e. Load r ix e => Array r ix e -> Int
elemsCount Vector r e
v
    go :: Int -> Sz1
go !Int
i
      | Int
i Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
k Bool -> Bool -> Bool
&& e -> Bool
f (Vector r e -> Int -> e
forall r ix e. Source r ix e => Array r ix e -> Int -> e
unsafeLinearIndex Vector r e
v Int
i) = Int -> Sz1
go (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
      | Bool
otherwise = Int -> Sz1
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 :: Stream r Ix1 e => Sz1 -> Vector r e -> Vector DS e
sdrop :: Sz1 -> Vector r e -> Vector DS e
sdrop Sz1
n = Steps Id e -> Vector DS e
forall e. Steps Id e -> Array DS Int e
fromSteps (Steps Id e -> Vector DS e)
-> (Vector r e -> Steps Id e) -> Vector r e -> Vector DS e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Steps Id e -> Steps Id e
forall (m :: * -> *) a. Monad m => Int -> Steps m a -> Steps m a
S.drop (Sz1 -> Int
forall ix. Sz ix -> ix
unSz Sz1
n) (Steps Id e -> Steps Id e)
-> (Vector r e -> Steps Id e) -> Vector r e -> Steps Id e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector r e -> Steps Id e
forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream
{-# INLINE sdrop #-}

-- |
--
-- ==== __Examples__
--
-- @since 0.5.0
drop' :: Source r Ix1 e => Sz1 -> Vector r e -> Vector r e
drop' :: Sz1 -> Vector r e -> Vector r e
drop' Sz1
k = (SomeException -> Vector r e)
-> (Vector r e -> Vector r e)
-> Either SomeException (Vector r e)
-> Vector r e
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either SomeException -> Vector r e
forall a e. Exception e => e -> a
throw Vector r e -> Vector r e
forall a. a -> a
id (Either SomeException (Vector r e) -> Vector r e)
-> (Vector r e -> Either SomeException (Vector r e))
-> Vector r e
-> Vector r e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Sz1 -> Vector r e -> Either SomeException (Vector r e)
forall r e (m :: * -> *).
(Source r Int e, MonadThrow m) =>
Sz1 -> Vector r e -> m (Vector r e)
dropM Sz1
k
{-# INLINE drop' #-}

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


-- | Samel as `sliceAt`, except it never fails.
--
--
-- ==== __Examples__
--
-- @since 0.5.0
sliceAt :: Source r Ix1 e => Sz1 -> Vector r e -> (Vector r e, Vector r e)
sliceAt :: Sz1 -> Vector r e -> (Vector r e, Vector r e)
sliceAt (Sz Int
k) Vector r e
v = (Sz1 -> Vector r e -> Vector r e
forall r e. Source r Int e => Sz1 -> Vector r e -> Vector r e
unsafeTake Sz1
d Vector r e
v, Sz1 -> Vector r e -> Vector r e
forall r e. Source r Int e => Sz1 -> Vector r e -> Vector r e
unsafeDrop Sz1
d Vector r e
v)
  where
    !n :: Int
n = Sz1 -> Int
coerce (Vector r e -> Sz1
forall r ix e. Load r ix e => Array r ix e -> Sz ix
size Vector r e
v)
    !d :: Sz1
d = Int -> Sz1
forall ix. ix -> Sz ix
SafeSz (Int -> Int -> Int
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' :: Source r Ix1 e => Sz1 -> Vector r e -> (Vector r e, Vector r e)
sliceAt' :: Sz1 -> Vector r e -> (Vector r e, Vector r e)
sliceAt' Sz1
k = (SomeException -> (Vector r e, Vector r e))
-> ((Vector r e, Vector r e) -> (Vector r e, Vector r e))
-> Either SomeException (Vector r e, Vector r e)
-> (Vector r e, Vector r e)
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either SomeException -> (Vector r e, Vector r e)
forall a e. Exception e => e -> a
throw (Vector r e, Vector r e) -> (Vector r e, Vector r e)
forall a. a -> a
id (Either SomeException (Vector r e, Vector r e)
 -> (Vector r e, Vector r e))
-> (Vector r e -> Either SomeException (Vector r e, Vector r e))
-> Vector r e
-> (Vector r e, Vector r e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Sz1 -> Vector r e -> Either SomeException (Vector r e, Vector r e)
forall r e (m :: * -> *).
(Source r Int 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 :: (Source r Ix1 e, MonadThrow m) => Sz1 -> Vector r e -> m (Vector r e, Vector r e)
sliceAtM :: Sz1 -> Vector r e -> m (Vector r e, Vector r e)
sliceAtM Sz1
k Vector r e
v = do
  Vector r e
l <- Sz1 -> Vector r e -> m (Vector r e)
forall r e (m :: * -> *).
(Source r Int e, MonadThrow m) =>
Sz1 -> Vector r e -> m (Vector r e)
takeM Sz1
k Vector r e
v
  (Vector r e, Vector r e) -> m (Vector r e, Vector r e)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Vector r e
l, Sz1 -> Vector r e -> Vector r e
forall r e. Source r Int 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 :: Vector DS e
sempty = Steps Id e -> Vector DS e
forall e. Steps Id e -> Array DS Int e
DSArray Steps Id e
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 :: e -> Vector DS e
ssingleton = Steps Id e -> Vector DS e
forall e. Steps Id e -> Array DS Int e
DSArray (Steps Id e -> Vector DS e)
-> (e -> Steps Id e) -> e -> Vector DS e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. e -> Steps Id e
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 :: Load r Ix1 e => e -> Vector r e -> Vector DL e
cons :: e -> Vector r e -> Vector DL e
cons e
e Vector r e
v =
  let dv :: Vector DL e
dv = Vector r e -> Vector DL e
forall r ix e. Load r ix e => Array r ix e -> Array DL ix e
toLoadArray Vector r e
v
      load :: Scheduler m ()
-> Int -> (Int -> e -> m ()) -> (Int -> Sz1 -> e -> m ()) -> m ()
load Scheduler m ()
scheduler Int
startAt Int -> e -> m ()
uWrite Int -> Sz1 -> e -> m ()
uSet =
        Int -> e -> m ()
uWrite Int
startAt e
e m () -> m () -> m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Vector DL e
-> Scheduler m ()
-> Int
-> (Int -> e -> m ())
-> (Int -> Sz1 -> e -> m ())
-> m ()
forall ix e.
Array DL ix e
-> forall (m :: * -> *).
   Monad m =>
   Scheduler m ()
   -> Int -> (Int -> e -> m ()) -> (Int -> Sz1 -> e -> m ()) -> m ()
dlLoad Vector DL e
dv Scheduler m ()
scheduler (Int
startAt Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) Int -> e -> m ()
uWrite Int -> Sz1 -> e -> m ()
uSet
      {-# INLINE load #-}
   in Vector DL e
R:ArrayDLixe Int e
dv {dlSize :: Sz1
dlSize = Int -> Sz1
forall ix. ix -> Sz ix
SafeSz (Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Sz1 -> Int
forall ix. Sz ix -> ix
unSz (Vector DL e -> Sz1
forall ix e. Array DL ix e -> Sz ix
dlSize Vector DL e
dv)), dlLoad :: forall (m :: * -> *).
Monad m =>
Scheduler m ()
-> Int -> (Int -> e -> m ()) -> (Int -> Sz1 -> e -> m ()) -> m ()
dlLoad = forall (m :: * -> *).
Monad m =>
Scheduler m ()
-> Int -> (Int -> e -> m ()) -> (Int -> Sz1 -> e -> m ()) -> m ()
load}
{-# INLINE cons #-}

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



-- | Replicate the same element @n@ times
--
-- ==== __Examples__
--
-- @since 0.5.0
sreplicate :: Sz1 -> e -> Vector DS e
sreplicate :: Sz1 -> e -> Vector DS e
sreplicate (Sz Int
n) = Steps Id e -> Vector DS e
forall e. Steps Id e -> Array DS Int e
DSArray (Steps Id e -> Vector DS e)
-> (e -> Steps Id e) -> e -> Vector DS e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> e -> Steps Id e
forall (m :: * -> *) a. Monad m => Int -> a -> Steps m a
S.replicate Int
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 :: Comp -> Sz1 -> (Int -> e) -> Vector D e
generate = Comp -> Sz1 -> (Int -> e) -> Vector D e
forall r ix e.
Construct 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 :: Sz1 -> (Int -> e) -> Vector DS e
sgenerate (Sz Int
n) = Steps Id e -> Vector DS e
forall e. Steps Id e -> Array DS Int e
DSArray (Steps Id e -> Vector DS e)
-> ((Int -> e) -> Steps Id e) -> (Int -> e) -> Vector DS e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> (Int -> e) -> Steps Id e
forall (m :: * -> *) e. Monad m => Int -> (Int -> e) -> Steps m e
S.generate Int
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 :: (e -> e) -> e -> Vector DS e
siterate e -> e
f = Steps Id e -> Vector DS e
forall e. Steps Id e -> Array DS Int e
fromSteps (Steps Id e -> Vector DS e)
-> (e -> Steps Id e) -> e -> Vector DS e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (e -> Maybe (e, e)) -> e -> Steps Id e
forall (m :: * -> *) s e.
Monad m =>
(s -> Maybe (e, s)) -> s -> Steps m e
S.unfoldr (\e
a -> (e, e) -> Maybe (e, e)
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 :: Sz1 -> (e -> e) -> e -> Vector DS e
siterateN Sz1
n e -> e
f e
a = Steps Id e -> Vector DS e
forall e. Steps Id e -> Array DS Int e
fromSteps (Steps Id e -> Vector DS e) -> Steps Id e -> Vector DS e
forall a b. (a -> b) -> a -> b
$ Int -> (e -> e) -> e -> Steps Id e
forall (m :: * -> *) a.
Monad m =>
Int -> (a -> a) -> a -> Steps m a
S.iterateN (Sz1 -> Int
forall ix. Sz ix -> ix
unSz 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 :: Monad m => Sz1 -> m e -> m (Vector DS e)
sreplicateM :: Sz1 -> m e -> m (Vector DS e)
sreplicateM Sz1
n m e
f = Steps m e -> m (Vector DS e)
forall (m :: * -> *) e. Monad m => Steps m e -> m (Array DS Int e)
fromStepsM (Steps m e -> m (Vector DS e)) -> Steps m e -> m (Vector DS e)
forall a b. (a -> b) -> a -> b
$ Int -> m e -> Steps m e
forall (m :: * -> *) a. Monad m => Int -> m a -> Steps m a
S.replicateM (Sz1 -> Int
forall ix. Sz ix -> ix
unSz 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 :: Monad m => Sz1 -> (Ix1 -> m e) -> m (Vector DS e)
sgenerateM :: Sz1 -> (Int -> m e) -> m (Vector DS e)
sgenerateM Sz1
n Int -> m e
f = Steps m e -> m (Vector DS e)
forall (m :: * -> *) e. Monad m => Steps m e -> m (Array DS Int e)
fromStepsM (Steps m e -> m (Vector DS e)) -> Steps m e -> m (Vector DS e)
forall a b. (a -> b) -> a -> b
$ Int -> (Int -> m e) -> Steps m e
forall (m :: * -> *) a. Monad m => Int -> (Int -> m a) -> Steps m a
S.generateM (Sz1 -> Int
forall ix. Sz ix -> ix
unSz 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 :: Monad m => Sz1 -> (e -> m e) -> e -> m (Vector DS e)
siterateNM :: Sz1 -> (e -> m e) -> e -> m (Vector DS e)
siterateNM Sz1
n e -> m e
f e
a = Steps m e -> m (Vector DS e)
forall (m :: * -> *) e. Monad m => Steps m e -> m (Array DS Int e)
fromStepsM (Steps m e -> m (Vector DS e)) -> Steps m e -> m (Vector DS e)
forall a b. (a -> b) -> a -> b
$ Int -> (e -> m e) -> e -> Steps m e
forall (m :: * -> *) a.
Monad m =>
Int -> (a -> m a) -> a -> Steps m a
S.iterateNM (Sz1 -> Int
forall ix. Sz ix -> ix
unSz 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 :: (s -> Maybe (e, s)) -> s -> Vector DS e
sunfoldr :: (s -> Maybe (e, s)) -> s -> Vector DS e
sunfoldr s -> Maybe (e, s)
f = Steps Id e -> Vector DS e
forall e. Steps Id e -> Array DS Int e
DSArray (Steps Id e -> Vector DS e)
-> (s -> Steps Id e) -> s -> Vector DS e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (s -> Maybe (e, s)) -> s -> Steps Id e
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 ::
     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 :: Sz1 -> (s -> Maybe (e, s)) -> s -> Vector DS e
sunfoldrN (Sz Int
n) s -> Maybe (e, s)
f = Steps Id e -> Vector DS e
forall e. Steps Id e -> Array DS Int e
DSArray (Steps Id e -> Vector DS e)
-> (s -> Steps Id e) -> s -> Vector DS e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> (s -> Maybe (e, s)) -> s -> Steps Id e
forall (m :: * -> *) s e.
Monad m =>
Int -> (s -> Maybe (e, s)) -> s -> Steps m e
S.unfoldrN Int
n s -> Maybe (e, s)
f
{-# INLINE sunfoldrN #-}

-- | /O(n)/ - Same as `unfoldr`, 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 :: Monad m => (s -> m (Maybe (e, s))) -> s -> m (Vector DS e)
sunfoldrM :: (s -> m (Maybe (e, s))) -> s -> m (Vector DS e)
sunfoldrM s -> m (Maybe (e, s))
f = Steps m e -> m (Vector DS e)
forall (m :: * -> *) e. Monad m => Steps m e -> m (Array DS Int e)
fromStepsM (Steps m e -> m (Vector DS e))
-> (s -> Steps m e) -> s -> m (Vector DS e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (s -> m (Maybe (e, s))) -> s -> Steps m e
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 `unfoldrN`, 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 :: Monad m => Sz1 -> (s -> m (Maybe (e, s))) -> s -> m (Vector DS e)
sunfoldrNM :: Sz1 -> (s -> m (Maybe (e, s))) -> s -> m (Vector DS e)
sunfoldrNM (Sz Int
n) s -> m (Maybe (e, s))
f = Steps m e -> m (Vector DS e)
forall (m :: * -> *) e. Monad m => Steps m e -> m (Array DS Int e)
fromStepsM (Steps m e -> m (Vector DS e))
-> (s -> Steps m e) -> s -> m (Vector DS e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> (s -> m (Maybe (e, s))) -> s -> Steps m e
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 `unfoldrN`, 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 :: Sz1 -> (s -> (e, s)) -> s -> Vector DS e
sunfoldrExactN :: Sz1 -> (s -> (e, s)) -> s -> Vector DS e
sunfoldrExactN (Sz Int
n) s -> (e, s)
f = Steps Id e -> Vector DS e
forall e. Steps Id e -> Array DS Int e
fromSteps (Steps Id e -> Vector DS e)
-> (s -> Steps Id e) -> s -> Vector DS e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> (s -> (e, s)) -> s -> Steps Id e
forall (m :: * -> *) s a.
Monad m =>
Int -> (s -> (a, s)) -> s -> Steps m a
S.unfoldrExactN Int
n s -> (e, s)
f
{-# INLINE sunfoldrExactN #-}

-- | /O(n)/ - Similar to `unfoldrNM`, 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 :: Monad m => Sz1 -> (s -> m (e, s)) -> s -> m (Vector DS e)
sunfoldrExactNM :: Sz1 -> (s -> m (e, s)) -> s -> m (Vector DS e)
sunfoldrExactNM (Sz Int
n) s -> m (e, s)
f = Steps m e -> m (Vector DS e)
forall (m :: * -> *) e. Monad m => Steps m e -> m (Array DS Int e)
fromStepsM (Steps m e -> m (Vector DS e))
-> (s -> Steps m e) -> s -> m (Vector DS e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> (s -> m (e, s)) -> s -> Steps m e
forall (m :: * -> *) s a.
Monad m =>
Int -> (s -> m (a, s)) -> s -> Steps m a
S.unfoldrExactNM Int
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 :: e -> Sz1 -> Vector DS e
senumFromN e
x (Sz Int
n) = Steps Id e -> Vector DS e
forall e. Steps Id e -> Array DS Int e
DSArray (Steps Id e -> Vector DS e) -> Steps Id e -> Vector DS e
forall a b. (a -> b) -> a -> b
$ e -> e -> Int -> Steps Id e
forall a (m :: * -> *).
(Num a, Monad m) =>
a -> a -> Int -> Steps m a
S.enumFromStepN e
x e
1 Int
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 :: e -> e -> Sz1 -> Vector DS e
senumFromStepN e
x e
step (Sz Int
n) = Steps Id e -> Vector DS e
forall e. Steps Id e -> Array DS Int e
DSArray (Steps Id e -> Vector DS e) -> Steps Id e -> Vector DS e
forall a b. (a -> b) -> a -> b
$ e -> e -> Int -> Steps Id e
forall a (m :: * -> *).
(Num a, Monad m) =>
a -> a -> Int -> Steps m a
S.enumFromStepN e
x e
step Int
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 :: (Stream r1 Ix1 e, Stream r2 Ix1 e) => Vector r1 e -> Vector r2 e -> Vector DS e
sappend :: Vector r1 e -> Vector r2 e -> Vector DS e
sappend Vector r1 e
a1 Vector r2 e
a2 = Steps Id e -> Vector DS e
forall e. Steps Id e -> Array DS Int e
fromSteps (Vector r1 e -> Steps Id e
forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
toStream Vector r1 e
a1 Steps Id e -> Steps Id e -> Steps Id e
forall (m :: * -> *) e.
Monad m =>
Steps m e -> Steps m e -> Steps m e
`S.append` Vector r2 e -> Steps Id e
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 :: Stream r Ix1 e => [Vector r e] -> Vector DS e
sconcat :: [Vector r e] -> Vector DS e
sconcat = Steps Id e -> Vector DS e
forall e. Steps Id e -> Array DS Int e
DSArray (Steps Id e -> Vector DS e)
-> ([Vector r e] -> Steps Id e) -> [Vector r e] -> Vector DS e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Vector r e -> Steps Id e) -> [Vector r e] -> Steps Id e
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap Vector r e -> Steps Id e
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 :: [e] -> Vector DS e
sfromList = Steps Id e -> Vector DS e
forall e. Steps Id e -> Array DS Int e
fromSteps (Steps Id e -> Vector DS e)
-> ([e] -> Steps Id e) -> [e] -> Vector DS e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [e] -> Steps Id e
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 :: Sz1 -> [e] -> Vector DS e
sfromListN (Sz Int
n) = Steps Id e -> Vector DS e
forall e. Steps Id e -> Array DS Int e
fromSteps (Steps Id e -> Vector DS e)
-> ([e] -> Steps Id e) -> [e] -> Vector DS e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> [e] -> Steps Id e
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 :: Stream r ix e => Array r ix e -> [e]
stoList :: Array r ix e -> [e]
stoList = Steps Id e -> [e]
forall e. Steps Id e -> [e]
S.toList (Steps Id e -> [e])
-> (Array r ix e -> Steps Id e) -> Array r ix e -> [e]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Array r ix e -> Steps Id e
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 :: S.Stream r ix e => (e -> Bool) -> Array r ix e -> Vector DS e
sfilter :: (e -> Bool) -> Array r ix e -> Vector DS e
sfilter e -> Bool
f = Steps Id e -> Vector DS e
forall e. Steps Id e -> Array DS Int e
DSArray (Steps Id e -> Vector DS e)
-> (Array r ix e -> Steps Id e) -> Array r ix e -> Vector DS e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (e -> Bool) -> Steps Id e -> Steps Id e
forall (m :: * -> *) a.
Monad m =>
(a -> Bool) -> Steps m a -> Steps m a
S.filter e -> Bool
f (Steps Id e -> Steps Id e)
-> (Array r ix e -> Steps Id e) -> Array r ix e -> Steps Id e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Array r ix e -> Steps Id e
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 :: Stream r ix a => (ix -> a -> Bool) -> Array r ix a -> Vector DS a
sifilter :: (ix -> a -> Bool) -> Array r ix a -> Vector DS a
sifilter ix -> a -> Bool
f =
  (ix -> a -> Maybe a) -> Array r ix a -> Vector DS a
forall r ix a b.
Stream r ix a =>
(ix -> a -> Maybe b) -> Array r ix a -> Vector DS b
simapMaybe ((ix -> a -> Maybe a) -> Array r ix a -> Vector DS a)
-> (ix -> a -> Maybe a) -> Array r ix a -> Vector DS a
forall a b. (a -> b) -> a -> b
$ \ix
ix a
e ->
    if ix -> a -> Bool
f ix
ix a
e
      then a -> Maybe a
forall a. a -> Maybe a
Just a
e
      else Maybe a
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 :: (S.Stream r ix e, Applicative f) => (e -> f Bool) -> Array r ix e -> f (Vector DS e)
sfilterM :: (e -> f Bool) -> Array r ix e -> f (Vector DS e)
sfilterM e -> f Bool
f Array r ix e
arr = Steps Id e -> Vector DS e
forall e. Steps Id e -> Array DS Int e
DSArray (Steps Id e -> Vector DS e) -> f (Steps Id e) -> f (Vector DS e)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (e -> f Bool) -> Steps Id e -> f (Steps Id e)
forall (m :: * -> *) (f :: * -> *) e.
(Monad m, Applicative f) =>
(e -> f Bool) -> Steps Id e -> f (Steps m e)
S.filterA e -> f Bool
f (Array r ix e -> Steps Id e
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 ::
     (Stream r ix a, Applicative f) => (ix -> a -> f Bool) -> Array r ix a -> f (Vector DS a)
sifilterM :: (ix -> a -> f Bool) -> Array r ix a -> f (Vector DS a)
sifilterM ix -> a -> f Bool
f =
  (ix -> a -> f (Maybe a)) -> Array r ix a -> f (Vector DS a)
forall r ix a (f :: * -> *) b.
(Stream r ix a, Applicative f) =>
(ix -> a -> f (Maybe b)) -> Array r ix a -> f (Vector DS b)
simapMaybeM ((ix -> a -> f (Maybe a)) -> Array r ix a -> f (Vector DS a))
-> (ix -> a -> f (Maybe a)) -> Array r ix a -> f (Vector DS a)
forall a b. (a -> b) -> a -> b
$ \ix
ix a
e ->
    (\Bool
p ->
       if Bool
p
         then a -> Maybe a
forall a. a -> Maybe a
Just a
e
         else Maybe a
forall a. Maybe a
Nothing) (Bool -> Maybe a) -> f Bool -> f (Maybe a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
    ix -> a -> f Bool
f ix
ix a
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 :: S.Stream r ix a => (a -> Maybe b) -> Array r ix a -> Vector DS b
smapMaybe :: (a -> Maybe b) -> Array r ix a -> Vector DS b
smapMaybe a -> Maybe b
f = Steps Id b -> Vector DS b
forall e. Steps Id e -> Array DS Int e
DSArray (Steps Id b -> Vector DS b)
-> (Array r ix a -> Steps Id b) -> Array r ix a -> Vector DS b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> Maybe b) -> Steps Id a -> Steps Id b
forall (m :: * -> *) a e.
Monad m =>
(a -> Maybe e) -> Steps m a -> Steps m e
S.mapMaybe a -> Maybe b
f (Steps Id a -> Steps Id b)
-> (Array r ix a -> Steps Id a) -> Array r ix a -> Steps Id b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Array r ix a -> Steps Id a
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 :: Stream r ix a => (ix -> a -> Maybe b) -> Array r ix a -> Vector DS b
simapMaybe :: (ix -> a -> Maybe b) -> Array r ix a -> Vector DS b
simapMaybe ix -> a -> Maybe b
f = Steps Id b -> Vector DS b
forall e. Steps Id e -> Array DS Int e
DSArray (Steps Id b -> Vector DS b)
-> (Array r ix a -> Steps Id b) -> Array r ix a -> Vector DS b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((ix, a) -> Maybe b) -> Steps Id (ix, a) -> Steps Id b
forall (m :: * -> *) a e.
Monad m =>
(a -> Maybe e) -> Steps m a -> Steps m e
S.mapMaybe ((ix -> a -> Maybe b) -> (ix, a) -> Maybe b
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry ix -> a -> Maybe b
f) (Steps Id (ix, a) -> Steps Id b)
-> (Array r ix a -> Steps Id (ix, a)) -> Array r ix a -> Steps Id b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Array r ix a -> Steps Id (ix, a)
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 ::
     (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)) -> Array r ix a -> f (Vector DS b)
simapMaybeM ix -> a -> f (Maybe b)
f = (Steps Id b -> Vector DS b) -> f (Steps Id b) -> f (Vector DS b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Steps Id b -> Vector DS b
forall e. Steps Id e -> Array DS Int e
DSArray (f (Steps Id b) -> f (Vector DS b))
-> (Array r ix a -> f (Steps Id b))
-> Array r ix a
-> f (Vector DS b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((ix, a) -> f (Maybe b)) -> Steps Id (ix, a) -> f (Steps Id b)
forall (m :: * -> *) (f :: * -> *) a e.
(Monad m, Applicative f) =>
(a -> f (Maybe e)) -> Steps Id a -> f (Steps m e)
S.mapMaybeA ((ix -> a -> f (Maybe b)) -> (ix, a) -> f (Maybe b)
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry ix -> a -> f (Maybe b)
f) (Steps Id (ix, a) -> f (Steps Id b))
-> (Array r ix a -> Steps Id (ix, a))
-> Array r ix a
-> f (Steps Id b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Array r ix a -> Steps Id (ix, a)
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 :: S.Stream r ix (Maybe a) => Array r ix (Maybe a) -> Vector DS a
scatMaybes :: Array r ix (Maybe a) -> Vector DS a
scatMaybes = (Maybe a -> Maybe a) -> Array r ix (Maybe a) -> Vector DS a
forall r ix a b.
Stream r ix a =>
(a -> Maybe b) -> Array r ix a -> Vector DS b
smapMaybe Maybe a -> Maybe a
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 ::
     (S.Stream r ix a, Applicative f) => (a -> f (Maybe b)) -> Array r ix a -> f (Vector DS b)
smapMaybeM :: (a -> f (Maybe b)) -> Array r ix a -> f (Vector DS b)
smapMaybeM a -> f (Maybe b)
f = (Steps Id b -> Vector DS b) -> f (Steps Id b) -> f (Vector DS b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Steps Id b -> Vector DS b
forall e. Steps Id e -> Array DS Int e
DSArray (f (Steps Id b) -> f (Vector DS b))
-> (Array r ix a -> f (Steps Id b))
-> Array r ix a
-> f (Vector DS b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> f (Maybe b)) -> Steps Id a -> f (Steps Id b)
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 (Steps Id a -> f (Steps Id b))
-> (Array r ix a -> Steps Id a) -> Array r ix a -> f (Steps Id b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Array r ix a -> Steps Id a
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 :: S.Stream r ix a => (a -> b) -> Array r ix a -> Vector DS b
smap :: (a -> b) -> Array r ix a -> Vector DS b
smap a -> b
f = Steps Id b -> Vector DS b
forall e. Steps Id e -> Array DS Int e
fromSteps (Steps Id b -> Vector DS b)
-> (Array r ix a -> Steps Id b) -> Array r ix a -> Vector DS b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> b) -> Steps Id a -> Steps Id b
forall (m :: * -> *) e a.
Monad m =>
(e -> a) -> Steps m e -> Steps m a
S.map a -> b
f (Steps Id a -> Steps Id b)
-> (Array r ix a -> Steps Id a) -> Array r ix a -> Steps Id b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Array r ix a -> Steps Id a
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 :: S.Stream r ix a => (ix -> a -> b) -> Array r ix a -> Vector DS b
simap :: (ix -> a -> b) -> Array r ix a -> Vector DS b
simap ix -> a -> b
f = Steps Id b -> Vector DS b
forall e. Steps Id e -> Array DS Int e
fromSteps (Steps Id b -> Vector DS b)
-> (Array r ix a -> Steps Id b) -> Array r ix a -> Vector DS b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((ix, a) -> b) -> Steps Id (ix, a) -> Steps Id b
forall (m :: * -> *) e a.
Monad m =>
(e -> a) -> Steps m e -> Steps m a
S.map ((ix -> a -> b) -> (ix, a) -> b
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry ix -> a -> b
f) (Steps Id (ix, a) -> Steps Id b)
-> (Array r ix a -> Steps Id (ix, a)) -> Array r ix a -> Steps Id b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Array r ix a -> Steps Id (ix, a)
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 :: (S.Stream r ix a, Applicative f) => (a -> f b) -> Array r ix a -> f (Vector DS b)
straverse :: (a -> f b) -> Array r ix a -> f (Vector DS b)
straverse a -> f b
f = (Steps Id b -> Vector DS b) -> f (Steps Id b) -> f (Vector DS b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Steps Id b -> Vector DS b
forall e. Steps Id e -> Array DS Int e
fromSteps (f (Steps Id b) -> f (Vector DS b))
-> (Array r ix a -> f (Steps Id b))
-> Array r ix a
-> f (Vector DS b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> f b) -> Steps Id a -> f (Steps Id b)
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 (Steps Id a -> f (Steps Id b))
-> (Array r ix a -> Steps Id a) -> Array r ix a -> f (Steps Id b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Array r ix a -> Steps Id a
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 :: (S.Stream r ix a, Applicative f) => (ix -> a -> f b) -> Array r ix a -> f (Vector DS b)
sitraverse :: (ix -> a -> f b) -> Array r ix a -> f (Vector DS b)
sitraverse ix -> a -> f b
f = (Steps Id b -> Vector DS b) -> f (Steps Id b) -> f (Vector DS b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Steps Id b -> Vector DS b
forall e. Steps Id e -> Array DS Int e
fromSteps (f (Steps Id b) -> f (Vector DS b))
-> (Array r ix a -> f (Steps Id b))
-> Array r ix a
-> f (Vector DS b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((ix, a) -> f b) -> Steps Id (ix, a) -> f (Steps Id b)
forall (m :: * -> *) (f :: * -> *) e a.
(Monad m, Applicative f) =>
(e -> f a) -> Steps Id e -> f (Steps m a)
S.traverse ((ix -> a -> f b) -> (ix, a) -> f b
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry ix -> a -> f b
f) (Steps Id (ix, a) -> f (Steps Id b))
-> (Array r ix a -> Steps Id (ix, a))
-> Array r ix a
-> f (Steps Id b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Array r ix a -> Steps Id (ix, a)
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 :: (S.Stream r ix a, Monad m) => (a -> m b) -> Array r ix a -> m (Vector DS b)
smapM :: (a -> m b) -> Array r ix a -> m (Vector DS b)
smapM a -> m b
f = Steps m b -> m (Vector DS b)
forall (m :: * -> *) e. Monad m => Steps m e -> m (Array DS Int e)
fromStepsM (Steps m b -> m (Vector DS b))
-> (Array r ix a -> Steps m b) -> Array r ix a -> m (Vector DS b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> m b) -> Steps m a -> Steps m b
forall (m :: * -> *) e a.
Monad m =>
(e -> m a) -> Steps m e -> Steps m a
S.mapM a -> m b
f (Steps m a -> Steps m b)
-> (Array r ix a -> Steps m a) -> Array r ix a -> Steps m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Steps Id a -> Steps m a
forall (m :: * -> *) e. Monad m => Steps Id e -> Steps m e
S.transStepsId (Steps Id a -> Steps m a)
-> (Array r ix a -> Steps Id a) -> Array r ix a -> Steps m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Array r ix a -> Steps Id a
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 :: (S.Stream r ix a, Monad m) => (ix -> a -> m b) -> Array r ix a -> m (Vector DS b)
simapM :: (ix -> a -> m b) -> Array r ix a -> m (Vector DS b)
simapM ix -> a -> m b
f = Steps m b -> m (Vector DS b)
forall (m :: * -> *) e. Monad m => Steps m e -> m (Array DS Int e)
fromStepsM (Steps m b -> m (Vector DS b))
-> (Array r ix a -> Steps m b) -> Array r ix a -> m (Vector DS b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((ix, a) -> m b) -> Steps m (ix, a) -> Steps m b
forall (m :: * -> *) e a.
Monad m =>
(e -> m a) -> Steps m e -> Steps m a
S.mapM ((ix -> a -> m b) -> (ix, a) -> m b
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry ix -> a -> m b
f) (Steps m (ix, a) -> Steps m b)
-> (Array r ix a -> Steps m (ix, a)) -> Array r ix a -> Steps m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Steps Id (ix, a) -> Steps m (ix, a)
forall (m :: * -> *) e. Monad m => Steps Id e -> Steps m e
S.transStepsId (Steps Id (ix, a) -> Steps m (ix, a))
-> (Array r ix a -> Steps Id (ix, a))
-> Array r ix a
-> Steps m (ix, a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Array r ix a -> Steps Id (ix, a)
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_ :: (S.Stream r ix a, Monad m) => (a -> m b) -> Array r ix a -> m ()
smapM_ :: (a -> m b) -> Array r ix a -> m ()
smapM_ a -> m b
f = (a -> m b) -> Steps m a -> m ()
forall (m :: * -> *) e a.
Monad m =>
(e -> m a) -> Steps m e -> m ()
S.mapM_ a -> m b
f (Steps m a -> m ())
-> (Array r ix a -> Steps m a) -> Array r ix a -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Steps Id a -> Steps m a
forall (m :: * -> *) e. Monad m => Steps Id e -> Steps m e
S.transStepsId (Steps Id a -> Steps m a)
-> (Array r ix a -> Steps Id a) -> Array r ix a -> Steps m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Array r ix a -> Steps Id a
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_ :: (S.Stream r ix a, Monad m) => (ix -> a -> m b) -> Array r ix a -> m ()
simapM_ :: (ix -> a -> m b) -> Array r ix a -> m ()
simapM_ ix -> a -> m b
f = ((ix, a) -> m b) -> Steps m (ix, a) -> m ()
forall (m :: * -> *) e a.
Monad m =>
(e -> m a) -> Steps m e -> m ()
S.mapM_ ((ix -> a -> m b) -> (ix, a) -> m b
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry ix -> a -> m b
f) (Steps m (ix, a) -> m ())
-> (Array r ix a -> Steps m (ix, a)) -> Array r ix a -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Steps Id (ix, a) -> Steps m (ix, a)
forall (m :: * -> *) e. Monad m => Steps Id e -> Steps m e
S.transStepsId (Steps Id (ix, a) -> Steps m (ix, a))
-> (Array r ix a -> Steps Id (ix, a))
-> Array r ix a
-> Steps m (ix, a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Array r ix a -> Steps Id (ix, a)
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 :: (S.Stream r ix a, Monad m) => Array r ix a -> (a -> m b) -> m (Vector DS b)
sforM :: Array r ix a -> (a -> m b) -> m (Vector DS b)
sforM = ((a -> m b) -> Array r ix a -> m (Vector DS b))
-> Array r ix a -> (a -> m b) -> m (Vector DS b)
forall a b c. (a -> b -> c) -> b -> a -> c
flip (a -> m b) -> Array r ix a -> m (Vector DS b)
forall r ix a (m :: * -> *) b.
(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 :: (S.Stream r ix a, Monad m) => Array r ix a -> (ix -> a -> m b) -> m (Vector DS b)
siforM :: Array r ix a -> (ix -> a -> m b) -> m (Vector DS b)
siforM = ((ix -> a -> m b) -> Array r ix a -> m (Vector DS b))
-> Array r ix a -> (ix -> a -> m b) -> m (Vector DS b)
forall a b c. (a -> b -> c) -> b -> a -> c
flip (ix -> a -> m b) -> Array r ix a -> m (Vector DS b)
forall r ix a (m :: * -> *) b.
(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_ :: Array r ix a -> (a -> m b) -> m ()
sforM_ = ((a -> m b) -> Array r ix a -> m ())
-> Array r ix a -> (a -> m b) -> m ()
forall a b c. (a -> b -> c) -> b -> a -> c
flip (a -> m b) -> Array r ix a -> m ()
forall r ix a (m :: * -> *) b.
(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_ :: (S.Stream r ix a, Monad m) => Array r ix a -> (ix -> a -> m b) -> m ()
siforM_ :: Array r ix a -> (ix -> a -> m b) -> m ()
siforM_ = ((ix -> a -> m b) -> Array r ix a -> m ())
-> Array r ix a -> (ix -> a -> m b) -> m ()
forall a b c. (a -> b -> c) -> b -> a -> c
flip (ix -> a -> m b) -> Array r ix a -> m ()
forall r ix a (m :: * -> *) b.
(Stream r ix a, Monad m) =>
(ix -> a -> m b) -> Array r ix a -> m ()
simapM_
{-# INLINE siforM_ #-}



-- | Zip two arrays in a row-major order together together into a flat vector. Resulting
-- length of a vector will be the smallest number of elements of the supplied arrays.
--
-- ==== __Examples__
--
-- @since 0.5.0
szip ::
     (S.Stream ra Ix1 a, S.Stream rb Ix1 b) => Vector ra a -> Vector rb b -> Vector DS (a, b)
szip :: Vector ra a -> Vector rb b -> Vector DS (a, b)
szip = (a -> b -> (a, b))
-> Vector ra a -> Vector rb b -> Vector DS (a, b)
forall ra a rb 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 #-}

-- |
--
-- @since 0.5.0
szip3 ::
     (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 :: Vector ra a -> Vector rb b -> Vector rc c -> Vector DS (a, b, c)
szip3 = (a -> b -> c -> (a, b, c))
-> Vector ra a -> Vector rb b -> Vector rc c -> Vector DS (a, b, c)
forall ra a rb b rc 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 #-}

-- |
--
-- @since 0.5.0
szip4 ::
     (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 :: Vector ra a
-> Vector rb b
-> Vector rc c
-> Vector rd d
-> Vector DS (a, b, c, d)
szip4 = (a -> b -> c -> d -> (a, b, c, d))
-> Vector ra a
-> Vector rb b
-> Vector rc c
-> Vector rd d
-> Vector DS (a, b, c, d)
forall ra a rb b rc c rd 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 #-}

-- |
--
-- @since 0.5.0
szip5 ::
     (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 :: Vector ra a
-> Vector rb b
-> Vector rc c
-> Vector rd d
-> Vector re e
-> Vector DS (a, b, c, d, e)
szip5 = (a -> b -> c -> d -> e -> (a, b, c, d, e))
-> Vector ra a
-> Vector rb b
-> Vector rc c
-> Vector rd d
-> Vector re e
-> Vector DS (a, b, c, d, e)
forall ra a rb b rc c rd d re 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 #-}

-- |
--
-- @since 0.5.0
szip6 ::
     ( 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 :: 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 = (a -> b -> c -> d -> e -> f -> (a, b, c, d, e, 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)
forall ra a rb b rc c rd d re e rf 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 #-}






-- |
--
-- ==== __Examples__
--
-- @since 0.5.0
szipWith ::
     (S.Stream ra Ix1 a, S.Stream rb Ix1 b)
  => (a -> b -> c)
  -> Vector ra a
  -> Vector rb b
  -> Vector DS c
szipWith :: (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 = Steps Id c -> Vector DS c
forall e. Steps Id e -> Array DS Int e
fromSteps (Steps Id c -> Vector DS c) -> Steps Id c -> Vector DS c
forall a b. (a -> b) -> a -> b
$ (a -> b -> c) -> Steps Id a -> Steps Id b -> Steps Id c
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 (Vector ra a -> Steps Id a
forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream Vector ra a
v1) (Vector rb b -> Steps Id b
forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream Vector rb b
v2)
{-# INLINE szipWith #-}

-- |
--
-- @since 0.5.0
szipWith3 ::
     (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 :: (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 = Steps Id d -> Vector DS d
forall e. Steps Id e -> Array DS Int e
fromSteps (Steps Id d -> Vector DS d) -> Steps Id d -> Vector DS d
forall a b. (a -> b) -> a -> b
$ (a -> b -> c -> d)
-> Steps Id a -> Steps Id b -> Steps Id c -> Steps Id d
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 (Vector ra a -> Steps Id a
forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream Vector ra a
v1) (Vector rb b -> Steps Id b
forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream Vector rb b
v2) (Vector rc c -> Steps Id c
forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream Vector rc c
v3)
{-# INLINE szipWith3 #-}

-- |
--
-- @since 0.5.0
szipWith4 ::
     (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 :: (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 =
  Steps Id e -> Vector DS e
forall e. Steps Id e -> Array DS Int e
fromSteps (Steps Id e -> Vector DS e) -> Steps Id e -> Vector DS e
forall a b. (a -> b) -> a -> b
$ (a -> b -> c -> d -> e)
-> Steps Id a
-> Steps Id b
-> Steps Id c
-> Steps Id d
-> Steps Id e
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 (Vector ra a -> Steps Id a
forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream Vector ra a
v1) (Vector rb b -> Steps Id b
forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream Vector rb b
v2) (Vector rc c -> Steps Id c
forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream Vector rc c
v3) (Vector rd d -> Steps Id d
forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream Vector rd d
v4)
{-# INLINE szipWith4 #-}

-- |
--
-- @since 0.5.0
szipWith5 ::
     (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 :: (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 =
  Steps Id f -> Vector DS f
forall e. Steps Id e -> Array DS Int e
fromSteps (Steps Id f -> Vector DS f) -> Steps Id f -> Vector DS f
forall a b. (a -> b) -> a -> b
$
  (a -> b -> c -> d -> e -> f)
-> Steps Id a
-> Steps Id b
-> Steps Id c
-> Steps Id d
-> Steps Id e
-> Steps Id f
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 (Vector ra a -> Steps Id a
forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream Vector ra a
v1) (Vector rb b -> Steps Id b
forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream Vector rb b
v2) (Vector rc c -> Steps Id c
forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream Vector rc c
v3) (Vector rd d -> Steps Id d
forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream Vector rd d
v4) (Vector re e -> Steps Id e
forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream Vector re e
v5)
{-# INLINE szipWith5 #-}

-- |
--
-- @since 0.5.0
szipWith6 ::
     ( 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 :: (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 =
  Steps Id g -> Vector DS g
forall e. Steps Id e -> Array DS Int e
fromSteps (Steps Id g -> Vector DS g) -> Steps Id g -> Vector DS g
forall a b. (a -> b) -> a -> b
$
  (a -> b -> c -> d -> e -> f -> g)
-> Steps Id a
-> Steps Id b
-> Steps Id c
-> Steps Id d
-> Steps Id e
-> Steps Id f
-> Steps Id g
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
    (Vector ra a -> Steps Id a
forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream Vector ra a
v1)
    (Vector rb b -> Steps Id b
forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream Vector rb b
v2)
    (Vector rc c -> Steps Id c
forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream Vector rc c
v3)
    (Vector rd d -> Steps Id d
forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream Vector rd d
v4)
    (Vector re e -> Steps Id e
forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream Vector re e
v5)
    (Vector rf f -> Steps Id f
forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream Vector rf f
v6)
{-# INLINE szipWith6 #-}

-- |
--
-- ==== __Examples__
--
-- @since 0.5.0
sizipWith ::
     (S.Stream ra Ix1 a, S.Stream rb Ix1 b)
  => (Ix1 -> a -> b -> c)
  -> Vector ra a
  -> Vector rb b
  -> Vector DS c
sizipWith :: (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 = Steps Id c -> Vector DS c
forall e. Steps Id e -> Array DS Int e
fromSteps (Steps Id c -> Vector DS c) -> Steps Id c -> Vector DS c
forall a b. (a -> b) -> a -> b
$ ((Int, a) -> b -> c)
-> Steps Id (Int, a) -> Steps Id b -> Steps Id c
forall (m :: * -> *) a b e.
Monad m =>
(a -> b -> e) -> Steps m a -> Steps m b -> Steps m e
S.zipWith ((Int -> a -> b -> c) -> (Int, a) -> b -> c
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Int -> a -> b -> c
f) (Vector ra a -> Steps Id (Int, a)
forall r ix e. Stream r ix e => Array r ix e -> Steps Id (ix, e)
S.toStreamIx Vector ra a
v1) (Vector rb b -> Steps Id b
forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream Vector rb b
v2)
{-# INLINE sizipWith #-}

-- |
--
-- @since 0.5.0
sizipWith3 ::
     (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 :: (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 =
  Steps Id d -> Vector DS d
forall e. Steps Id e -> Array DS Int e
fromSteps (Steps Id d -> Vector DS d) -> Steps Id d -> Vector DS d
forall a b. (a -> b) -> a -> b
$ ((Int, a) -> b -> c -> d)
-> Steps Id (Int, a) -> Steps Id b -> Steps Id c -> Steps Id d
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 ((Int -> a -> b -> c -> d) -> (Int, a) -> b -> c -> d
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Int -> a -> b -> c -> d
f) (Vector ra a -> Steps Id (Int, a)
forall r ix e. Stream r ix e => Array r ix e -> Steps Id (ix, e)
S.toStreamIx Vector ra a
v1) (Vector rb b -> Steps Id b
forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream Vector rb b
v2) (Vector rc c -> Steps Id c
forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream Vector rc c
v3)
{-# INLINE sizipWith3 #-}

-- |
--
-- @since 0.5.0
sizipWith4 ::
     (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 :: (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 =
  Steps Id e -> Vector DS e
forall e. Steps Id e -> Array DS Int e
fromSteps (Steps Id e -> Vector DS e) -> Steps Id e -> Vector DS e
forall a b. (a -> b) -> a -> b
$
  ((Int, a) -> b -> c -> d -> e)
-> Steps Id (Int, a)
-> Steps Id b
-> Steps Id c
-> Steps Id d
-> Steps Id e
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 ((Int -> a -> b -> c -> d -> e) -> (Int, a) -> b -> c -> d -> e
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Int -> a -> b -> c -> d -> e
f) (Vector ra a -> Steps Id (Int, a)
forall r ix e. Stream r ix e => Array r ix e -> Steps Id (ix, e)
S.toStreamIx Vector ra a
v1) (Vector rb b -> Steps Id b
forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream Vector rb b
v2) (Vector rc c -> Steps Id c
forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream Vector rc c
v3) (Vector rd d -> Steps Id d
forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream Vector rd d
v4)
{-# INLINE sizipWith4 #-}

-- |
--
-- @since 0.5.0
sizipWith5 ::
     (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 :: (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 =
  Steps Id f -> Vector DS f
forall e. Steps Id e -> Array DS Int e
fromSteps (Steps Id f -> Vector DS f) -> Steps Id f -> Vector DS f
forall a b. (a -> b) -> a -> b
$
  ((Int, a) -> b -> c -> d -> e -> f)
-> Steps Id (Int, a)
-> Steps Id b
-> Steps Id c
-> Steps Id d
-> Steps Id e
-> Steps Id f
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
    ((Int -> a -> b -> c -> d -> e -> f)
-> (Int, a) -> b -> c -> d -> e -> f
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Int -> a -> b -> c -> d -> e -> f
f)
    (Vector ra a -> Steps Id (Int, a)
forall r ix e. Stream r ix e => Array r ix e -> Steps Id (ix, e)
S.toStreamIx Vector ra a
v1)
    (Vector rb b -> Steps Id b
forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream Vector rb b
v2)
    (Vector rc c -> Steps Id c
forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream Vector rc c
v3)
    (Vector rd d -> Steps Id d
forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream Vector rd d
v4)
    (Vector re e -> Steps Id e
forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream Vector re e
v5)
{-# INLINE sizipWith5 #-}

-- |
--
-- @since 0.5.0
sizipWith6 ::
     ( 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 :: (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 =
  Steps Id g -> Vector DS g
forall e. Steps Id e -> Array DS Int e
fromSteps (Steps Id g -> Vector DS g) -> Steps Id g -> Vector DS g
forall a b. (a -> b) -> a -> b
$
  ((Int, a) -> b -> c -> d -> e -> f -> g)
-> Steps Id (Int, a)
-> Steps Id b
-> Steps Id c
-> Steps Id d
-> Steps Id e
-> Steps Id f
-> Steps Id g
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
    ((Int -> a -> b -> c -> d -> e -> f -> g)
-> (Int, a) -> b -> c -> d -> e -> f -> g
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Int -> a -> b -> c -> d -> e -> f -> g
f)
    (Vector ra a -> Steps Id (Int, a)
forall r ix e. Stream r ix e => Array r ix e -> Steps Id (ix, e)
S.toStreamIx Vector ra a
v1)
    (Vector rb b -> Steps Id b
forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream Vector rb b
v2)
    (Vector rc c -> Steps Id c
forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream Vector rc c
v3)
    (Vector rd d -> Steps Id d
forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream Vector rd d
v4)
    (Vector re e -> Steps Id e
forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream Vector re e
v5)
    (Vector rf f -> Steps Id f
forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream Vector rf f
v6)
{-# INLINE sizipWith6 #-}


-- |
--
-- ==== __Examples__
--
-- @since 0.5.0
szipWithM ::
     (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 :: (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 = Steps m c -> m (Vector DS c)
forall (m :: * -> *) e. Monad m => Steps m e -> m (Array DS Int e)
fromStepsM (Steps m c -> m (Vector DS c)) -> Steps m c -> m (Vector DS c)
forall a b. (a -> b) -> a -> b
$ (a -> b -> m c) -> Steps m a -> Steps m b -> Steps m c
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 (Vector ra a -> Steps m a
forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector ra a
v1) (Vector rb b -> Steps m b
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 #-}

-- |
--
-- @since 0.5.0
szipWith3M ::
     (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 :: (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 = Steps m d -> m (Vector DS d)
forall (m :: * -> *) e. Monad m => Steps m e -> m (Array DS Int e)
fromStepsM (Steps m d -> m (Vector DS d)) -> Steps m d -> m (Vector DS d)
forall a b. (a -> b) -> a -> b
$ (a -> b -> c -> m d)
-> Steps m a -> Steps m b -> Steps m c -> Steps m d
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 (Vector ra a -> Steps m a
forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector ra a
v1) (Vector rb b -> Steps m b
forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rb b
v2) (Vector rc c -> Steps m c
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 #-}

-- |
--
-- @since 0.5.0
szipWith4M ::
     (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 :: (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 =
  Steps m e -> m (Vector DS e)
forall (m :: * -> *) e. Monad m => Steps m e -> m (Array DS Int e)
fromStepsM (Steps m e -> m (Vector DS e)) -> Steps m e -> m (Vector DS e)
forall a b. (a -> b) -> a -> b
$ (a -> b -> c -> d -> m e)
-> Steps m a -> Steps m b -> Steps m c -> Steps m d -> Steps m e
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 (Vector ra a -> Steps m a
forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector ra a
v1) (Vector rb b -> Steps m b
forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rb b
v2) (Vector rc c -> Steps m c
forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rc c
v3) (Vector rd d -> Steps m d
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 #-}

-- |
--
-- @since 0.5.0
szipWith5M ::
     ( 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 :: (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 =
  Steps m f -> m (Vector DS f)
forall (m :: * -> *) e. Monad m => Steps m e -> m (Array DS Int e)
fromStepsM (Steps m f -> m (Vector DS f)) -> Steps m f -> m (Vector DS f)
forall a b. (a -> b) -> a -> b
$
  (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
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 (Vector ra a -> Steps m a
forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector ra a
v1) (Vector rb b -> Steps m b
forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rb b
v2) (Vector rc c -> Steps m c
forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rc c
v3) (Vector rd d -> Steps m d
forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rd d
v4) (Vector re e -> Steps m e
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 #-}

-- |
--
-- @since 0.5.0
szipWith6M ::
     ( 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 :: (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 =
  Steps m g -> m (Vector DS g)
forall (m :: * -> *) e. Monad m => Steps m e -> m (Array DS Int e)
fromStepsM (Steps m g -> m (Vector DS g)) -> Steps m g -> m (Vector DS g)
forall a b. (a -> b) -> a -> b
$
  (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
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
    (Vector ra a -> Steps m a
forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector ra a
v1)
    (Vector rb b -> Steps m b
forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rb b
v2)
    (Vector rc c -> Steps m c
forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rc c
v3)
    (Vector rd d -> Steps m d
forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rd d
v4)
    (Vector re e -> Steps m e
forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector re e
v5)
    (Vector rf f -> Steps m f
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 #-}


-- |
--
-- ==== __Examples__
--
-- @since 0.5.0
sizipWithM ::
     (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 :: (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 = Steps m c -> m (Vector DS c)
forall (m :: * -> *) e. Monad m => Steps m e -> m (Array DS Int e)
fromStepsM (Steps m c -> m (Vector DS c)) -> Steps m c -> m (Vector DS c)
forall a b. (a -> b) -> a -> b
$ ((Int, a) -> b -> m c)
-> Steps m (Int, a) -> Steps m b -> Steps m c
forall (m :: * -> *) a b c.
Monad m =>
(a -> b -> m c) -> Steps m a -> Steps m b -> Steps m c
S.zipWithM ((Int -> a -> b -> m c) -> (Int, a) -> b -> m c
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Int -> a -> b -> m c
f) (Vector ra a -> Steps m (Int, a)
forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m (ix, e)
toStreamIxM Vector ra a
v1) (Vector rb b -> Steps m b
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 #-}


-- |
--
-- @since 0.5.0
sizipWith3M ::
     (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 :: (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 =
  Steps m d -> m (Vector DS d)
forall (m :: * -> *) e. Monad m => Steps m e -> m (Array DS Int e)
fromStepsM (Steps m d -> m (Vector DS d)) -> Steps m d -> m (Vector DS d)
forall a b. (a -> b) -> a -> b
$ ((Int, a) -> b -> c -> m d)
-> Steps m (Int, a) -> Steps m b -> Steps m c -> Steps m d
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 ((Int -> a -> b -> c -> m d) -> (Int, a) -> b -> c -> m d
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Int -> a -> b -> c -> m d
f) (Vector ra a -> Steps m (Int, a)
forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m (ix, e)
toStreamIxM Vector ra a
v1) (Vector rb b -> Steps m b
forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rb b
v2) (Vector rc c -> Steps m c
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 #-}

-- |
--
-- @since 0.5.0
sizipWith4M ::
     (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 :: (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 =
  Steps m e -> m (Vector DS e)
forall (m :: * -> *) e. Monad m => Steps m e -> m (Array DS Int e)
fromStepsM (Steps m e -> m (Vector DS e)) -> Steps m e -> m (Vector DS e)
forall a b. (a -> b) -> a -> b
$
  ((Int, a) -> b -> c -> d -> m e)
-> Steps m (Int, a)
-> Steps m b
-> Steps m c
-> Steps m d
-> Steps m e
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 ((Int -> a -> b -> c -> d -> m e) -> (Int, a) -> b -> c -> d -> m e
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Int -> a -> b -> c -> d -> m e
f) (Vector ra a -> Steps m (Int, a)
forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m (ix, e)
toStreamIxM Vector ra a
v1) (Vector rb b -> Steps m b
forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rb b
v2) (Vector rc c -> Steps m c
forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rc c
v3) (Vector rd d -> Steps m d
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 #-}

-- |
--
-- @since 0.5.0
sizipWith5M ::
     ( 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 :: (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 =
  Steps m f -> m (Vector DS f)
forall (m :: * -> *) e. Monad m => Steps m e -> m (Array DS Int e)
fromStepsM (Steps m f -> m (Vector DS f)) -> Steps m f -> m (Vector DS f)
forall a b. (a -> b) -> a -> b
$
  ((Int, a) -> b -> c -> d -> e -> m f)
-> Steps m (Int, a)
-> Steps m b
-> Steps m c
-> Steps m d
-> Steps m e
-> Steps m f
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
    ((Int -> a -> b -> c -> d -> e -> m f)
-> (Int, a) -> b -> c -> d -> e -> m f
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Int -> a -> b -> c -> d -> e -> m f
f)
    (Vector ra a -> Steps m (Int, a)
forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m (ix, e)
toStreamIxM Vector ra a
v1)
    (Vector rb b -> Steps m b
forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rb b
v2)
    (Vector rc c -> Steps m c
forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rc c
v3)
    (Vector rd d -> Steps m d
forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rd d
v4)
    (Vector re e -> Steps m e
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 #-}

-- |
--
-- ==== __Examples__
--
-- @since 0.5.0
sizipWith6M ::
     ( 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 :: (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 =
  Steps m g -> m (Vector DS g)
forall (m :: * -> *) e. Monad m => Steps m e -> m (Array DS Int e)
fromStepsM (Steps m g -> m (Vector DS g)) -> Steps m g -> m (Vector DS g)
forall a b. (a -> b) -> a -> b
$
  ((Int, a) -> b -> c -> d -> e -> f -> m g)
-> Steps m (Int, a)
-> Steps m b
-> Steps m c
-> Steps m d
-> Steps m e
-> Steps m f
-> Steps m g
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
    ((Int -> a -> b -> c -> d -> e -> f -> m g)
-> (Int, a) -> b -> c -> d -> e -> f -> m g
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Int -> a -> b -> c -> d -> e -> f -> m g
f)
    (Vector ra a -> Steps m (Int, a)
forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m (ix, e)
toStreamIxM Vector ra a
v1)
    (Vector rb b -> Steps m b
forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rb b
v2)
    (Vector rc c -> Steps m c
forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rc c
v3)
    (Vector rd d -> Steps m d
forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rd d
v4)
    (Vector re e -> Steps m e
forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector re e
v5)
    (Vector rf f -> Steps m f
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 #-}


-- |
--
-- ==== __Examples__
--
-- @since 0.5.0
szipWithM_ ::
     (S.Stream ra Ix1 a, S.Stream rb Ix1 b, Monad m)
  => (a -> b -> m c)
  -> Vector ra a
  -> Vector rb b
  -> m ()
szipWithM_ :: (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 = (a -> b -> m c) -> Steps m a -> Steps m b -> m ()
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 (Vector ra a -> Steps m a
forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector ra a
v1) (Vector rb b -> Steps m b
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_ #-}

-- |
--
-- @since 0.5.0
szipWith3M_ ::
     (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_ :: (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 = (a -> b -> c -> m d) -> Steps m a -> Steps m b -> Steps m c -> m ()
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 (Vector ra a -> Steps m a
forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector ra a
v1) (Vector rb b -> Steps m b
forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rb b
v2) (Vector rc c -> Steps m c
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_ #-}

-- |
--
-- @since 0.5.0
szipWith4M_ ::
     (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_ :: (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 =
  (a -> b -> c -> d -> m e)
-> Steps m a -> Steps m b -> Steps m c -> Steps m d -> m ()
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 (Vector ra a -> Steps m a
forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector ra a
v1) (Vector rb b -> Steps m b
forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rb b
v2) (Vector rc c -> Steps m c
forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rc c
v3) (Vector rd d -> Steps m d
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_ #-}

-- |
--
-- @since 0.5.0
szipWith5M_ ::
     ( 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_ :: (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 =
  (a -> b -> c -> d -> e -> m f)
-> Steps m a
-> Steps m b
-> Steps m c
-> Steps m d
-> Steps m e
-> m ()
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 (Vector ra a -> Steps m a
forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector ra a
v1) (Vector rb b -> Steps m b
forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rb b
v2) (Vector rc c -> Steps m c
forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rc c
v3) (Vector rd d -> Steps m d
forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rd d
v4) (Vector re e -> Steps m e
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_ #-}

-- |
--
-- @since 0.5.0
szipWith6M_ ::
     ( 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_ :: (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 =
  (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 ()
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
    (Vector ra a -> Steps m a
forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector ra a
v1)
    (Vector rb b -> Steps m b
forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rb b
v2)
    (Vector rc c -> Steps m c
forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rc c
v3)
    (Vector rd d -> Steps m d
forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rd d
v4)
    (Vector re e -> Steps m e
forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector re e
v5)
    (Vector rf f -> Steps m f
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_ #-}




-- |
--
-- ==== __Examples__
--
-- @since 0.5.0
sizipWithM_ ::
     (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_ :: (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 = ((Int, a) -> b -> m c) -> Steps m (Int, a) -> Steps m b -> m ()
forall (m :: * -> *) a b c.
Monad m =>
(a -> b -> m c) -> Steps m a -> Steps m b -> m ()
S.zipWithM_ ((Int -> a -> b -> m c) -> (Int, a) -> b -> m c
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Int -> a -> b -> m c
f) (Vector ra a -> Steps m (Int, a)
forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m (ix, e)
toStreamIxM Vector ra a
v1) (Vector rb b -> Steps m b
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_ #-}


-- |
--
-- @since 0.5.0
sizipWith3M_ ::
     (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_ :: (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 = ((Int, a) -> b -> c -> m d)
-> Steps m (Int, a) -> Steps m b -> Steps m c -> m ()
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_ ((Int -> a -> b -> c -> m d) -> (Int, a) -> b -> c -> m d
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Int -> a -> b -> c -> m d
f) (Vector ra a -> Steps m (Int, a)
forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m (ix, e)
toStreamIxM Vector ra a
v1) (Vector rb b -> Steps m b
forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rb b
v2) (Vector rc c -> Steps m c
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_ #-}

-- |
--
-- @since 0.5.0
sizipWith4M_ ::
     (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_ :: (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 =
  ((Int, a) -> b -> c -> d -> m e)
-> Steps m (Int, a) -> Steps m b -> Steps m c -> Steps m d -> m ()
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_ ((Int -> a -> b -> c -> d -> m e) -> (Int, a) -> b -> c -> d -> m e
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Int -> a -> b -> c -> d -> m e
f) (Vector ra a -> Steps m (Int, a)
forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m (ix, e)
toStreamIxM Vector ra a
v1) (Vector rb b -> Steps m b
forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rb b
v2) (Vector rc c -> Steps m c
forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rc c
v3) (Vector rd d -> Steps m d
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_ #-}

-- |
--
-- @since 0.5.0
sizipWith5M_ ::
     ( 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_ :: (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 =
  ((Int, a) -> b -> c -> d -> e -> m f)
-> Steps m (Int, a)
-> Steps m b
-> Steps m c
-> Steps m d
-> Steps m e
-> m ()
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_
    ((Int -> a -> b -> c -> d -> e -> m f)
-> (Int, a) -> b -> c -> d -> e -> m f
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Int -> a -> b -> c -> d -> e -> m f
f)
    (Vector ra a -> Steps m (Int, a)
forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m (ix, e)
toStreamIxM Vector ra a
v1)
    (Vector rb b -> Steps m b
forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rb b
v2)
    (Vector rc c -> Steps m c
forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rc c
v3)
    (Vector rd d -> Steps m d
forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rd d
v4)
    (Vector re e -> Steps m e
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_ #-}

-- |
--
-- @since 0.5.0
sizipWith6M_ ::
     ( 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_ :: (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 =
  ((Int, a) -> b -> c -> d -> e -> f -> m g)
-> Steps m (Int, a)
-> Steps m b
-> Steps m c
-> Steps m d
-> Steps m e
-> Steps m f
-> m ()
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_
    ((Int -> a -> b -> c -> d -> e -> f -> m g)
-> (Int, a) -> b -> c -> d -> e -> f -> m g
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Int -> a -> b -> c -> d -> e -> f -> m g
f)
    (Vector ra a -> Steps m (Int, a)
forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m (ix, e)
toStreamIxM Vector ra a
v1)
    (Vector rb b -> Steps m b
forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rb b
v2)
    (Vector rc c -> Steps m c
forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rc c
v3)
    (Vector rd d -> Steps m d
forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector rd d
v4)
    (Vector re e -> Steps m e
forall r ix e (m :: * -> *).
(Stream r ix e, Monad m) =>
Array r ix e -> Steps m e
toStreamM Vector re e
v5)
    (Vector rf f -> Steps m f
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_ #-}





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

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

-- |
--
-- ==== __Examples__
--
-- @since 0.5.0
sfoldlM_ :: (Stream r ix e, Monad m) => (a -> e -> m a) -> a -> Array r ix e -> m ()
sfoldlM_ :: (a -> e -> m a) -> a -> Array r ix e -> m ()
sfoldlM_ a -> e -> m a
f a
acc = m a -> m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (m a -> m ()) -> (Array r ix e -> m a) -> Array r ix e -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> e -> m a) -> a -> Array r ix e -> m a
forall r ix e (m :: * -> *) a.
(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' :: Stream r ix e => (e -> e -> e) -> Array r ix e -> e
sfoldl1' :: (e -> e -> e) -> Array r ix e -> e
sfoldl1' e -> e -> e
f = (SomeException -> e) -> (e -> e) -> Either SomeException e -> e
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either SomeException -> e
forall a e. Exception e => e -> a
throw e -> e
forall a. a -> a
id (Either SomeException e -> e)
-> (Array r ix e -> Either SomeException e) -> Array r ix e -> e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (e -> e -> Either SomeException e)
-> Array r ix e -> Either SomeException e
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 -> Either SomeException e
forall (f :: * -> *) a. Applicative f => a -> f a
pure (e -> Either SomeException e)
-> (e -> e) -> e -> Either SomeException e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. e -> e -> e
f e
e)
{-# INLINE sfoldl1' #-}

-- |
--
-- ==== __Examples__
--
-- @since 0.5.0
sfoldl1M :: (Stream r ix e, MonadThrow m) => (e -> e -> m e) -> Array r ix e -> m e
sfoldl1M :: (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 = Steps Id e -> Steps m e
forall (m :: * -> *) e. Monad m => Steps Id e -> Steps m e
S.transStepsId (Steps Id e -> Steps m e) -> Steps Id e -> Steps m e
forall a b. (a -> b) -> a -> b
$ Array r ix e -> Steps Id e
forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
toStream Array r ix e
arr
  Bool
nullStream <- Steps m e -> m Bool
forall (m :: * -> *) a. Monad m => Steps m a -> m Bool
S.null Steps m e
str
  Bool -> m () -> m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
nullStream (m () -> m ()) -> m () -> m ()
forall a b. (a -> b) -> a -> b
$ SizeException -> m ()
forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwM (SizeException -> m ()) -> SizeException -> m ()
forall a b. (a -> b) -> a -> b
$ Sz ix -> SizeException
forall ix. Index ix => Sz ix -> SizeException
SizeEmptyException (Array r ix e -> Sz ix
forall r ix e. Load r ix e => Array r ix e -> Sz ix
size Array r ix e
arr)
  (e -> e -> m e) -> Steps m e -> m e
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_ :: (Stream r ix e, MonadThrow m) => (e -> e -> m e) -> Array r ix e -> m ()
sfoldl1M_ :: (e -> e -> m e) -> Array r ix e -> m ()
sfoldl1M_ e -> e -> m e
f = m e -> m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (m e -> m ()) -> (Array r ix e -> m e) -> Array r ix e -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (e -> e -> m e) -> Array r ix e -> m e
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 :: Stream r ix e => (a -> ix -> e -> a) -> a -> Array r ix e -> a
sifoldl :: (a -> ix -> e -> a) -> a -> Array r ix e -> a
sifoldl a -> ix -> e -> a
f a
acc = Id a -> a
forall a. Id a -> a
S.unId (Id a -> a) -> (Array r ix e -> Id a) -> Array r ix e -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> (ix, e) -> a) -> a -> Steps Id (ix, e) -> Id a
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 (Steps Id (ix, e) -> Id a)
-> (Array r ix e -> Steps Id (ix, e)) -> Array r ix e -> Id a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Array r ix e -> Steps Id (ix, e)
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 :: (Stream r ix e, Monad m) => (a -> ix -> e -> m a) -> a -> Array r ix e -> m a
sifoldlM :: (a -> ix -> e -> m a) -> a -> Array r ix e -> m a
sifoldlM a -> ix -> e -> m a
f a
acc = (a -> (ix, e) -> m a) -> a -> Steps m (ix, e) -> m a
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 (Steps m (ix, e) -> m a)
-> (Array r ix e -> Steps m (ix, e)) -> Array r ix e -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Steps Id (ix, e) -> Steps m (ix, e)
forall (m :: * -> *) e. Monad m => Steps Id e -> Steps m e
S.transStepsId (Steps Id (ix, e) -> Steps m (ix, e))
-> (Array r ix e -> Steps Id (ix, e))
-> Array r ix e
-> Steps m (ix, e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Array r ix e -> Steps Id (ix, e)
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_ :: (Stream r ix e, Monad m) => (a -> ix -> e -> m a) -> a -> Array r ix e -> m ()
sifoldlM_ :: (a -> ix -> e -> m a) -> a -> Array r ix e -> m ()
sifoldlM_ a -> ix -> e -> m a
f a
acc = m a -> m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (m a -> m ()) -> (Array r ix e -> m a) -> Array r ix e -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> ix -> e -> m a) -> a -> Array r ix e -> m a
forall r ix e (m :: * -> *) a.
(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 :: Stream r ix Bool => Array r ix Bool -> Bool
sor :: Array r ix Bool -> Bool
sor = Id Bool -> Bool
forall a. Id a -> a
S.unId (Id Bool -> Bool)
-> (Array r ix Bool -> Id Bool) -> Array r ix Bool -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Steps Id Bool -> Id Bool
forall (m :: * -> *). Monad m => Steps m Bool -> m Bool
S.or (Steps Id Bool -> Id Bool)
-> (Array r ix Bool -> Steps Id Bool) -> Array r ix Bool -> Id Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Array r ix Bool -> Steps Id Bool
forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
toStream
{-# INLINE sor #-}


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


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


-- |
--
-- ==== __Examples__
--
-- @since 0.5.0
sall :: Stream r ix e => (e -> Bool) -> Array r ix e -> Bool
sall :: (e -> Bool) -> Array r ix e -> Bool
sall e -> Bool
f = Id Bool -> Bool
forall a. Id a -> a
S.unId (Id Bool -> Bool)
-> (Array r ix e -> Id Bool) -> Array r ix e -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Steps Id Bool -> Id Bool
forall (m :: * -> *). Monad m => Steps m Bool -> m Bool
S.and (Steps Id Bool -> Id Bool)
-> (Array r ix e -> Steps Id Bool) -> Array r ix e -> Id Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (e -> Bool) -> Steps Id e -> Steps Id Bool
forall (m :: * -> *) e a.
Monad m =>
(e -> a) -> Steps m e -> Steps m a
S.map e -> Bool
f (Steps Id e -> Steps Id Bool)
-> (Array r ix e -> Steps Id e) -> Array r ix e -> Steps Id Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Array r ix e -> Steps Id e
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 :: (Num e, Stream r ix e) => Array r ix e -> e
ssum :: Array r ix e -> e
ssum = (e -> e -> e) -> e -> Array r ix e -> e
forall r ix e a.
Stream r ix e =>
(a -> e -> a) -> a -> Array r ix e -> a
sfoldl e -> e -> e
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 :: (Num e, Stream r ix e) => Array r ix e -> e
sproduct :: Array r ix e -> e
sproduct = (e -> e -> e) -> e -> Array r ix e -> e
forall r ix e a.
Stream r ix e =>
(a -> e -> a) -> a -> Array r ix e -> a
sfoldl e -> e -> e
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
-- >>> V.smaximum' (V.empty :: Vector D Int)
-- *** Exception: SizeEmptyException: (Sz1 0) corresponds to an empty array
--
-- @since 0.5.0
smaximum' :: (Ord e, Stream r ix e) => Array r ix e -> e
smaximum' :: Array r ix e -> e
smaximum' = (e -> e -> e) -> Array r ix e -> e
forall r ix e. Stream r ix e => (e -> e -> e) -> Array r ix e -> e
sfoldl1' e -> e -> e
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 :: (Ord e, Stream r ix e, MonadThrow m) => Array r ix e -> m e
smaximumM :: Array r ix e -> m e
smaximumM = (e -> e -> m e) -> Array r ix e -> m e
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 -> e -> m e
forall (f :: * -> *) a. Applicative f => a -> f a
pure (e -> e -> e
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
-- >>> V.sminimum' (V.empty :: Array D Ix2 Int)
-- *** Exception: SizeEmptyException: (Sz (0 :. 0)) corresponds to an empty array
--
-- @since 0.5.0
sminimum' :: (Ord e, Stream r ix e) => Array r ix e -> e
sminimum' :: Array r ix e -> e
sminimum' = (e -> e -> e) -> Array r ix e -> e
forall r ix e. Stream r ix e => (e -> e -> e) -> Array r ix e -> e
sfoldl1' e -> e -> e
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 :: (Ord e, Stream r ix e, MonadThrow m) => Array r ix e -> m e
sminimumM :: Array r ix e -> m e
sminimumM = (e -> e -> m e) -> Array r ix e -> m e
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 -> e -> m e
forall (f :: * -> *) a. Applicative f => a -> f a
pure (e -> e -> e
forall a. Ord a => a -> a -> a
min e
e e
acc))
{-# INLINE sminimumM #-}


-- | See `stake`.
--
-- @since 0.4.1
takeS :: Stream r ix e => Sz1 -> Array r ix e -> Array DS Ix1 e
takeS :: Sz1 -> Array r ix e -> Array DS Int e
takeS Sz1
n = Steps Id e -> Array DS Int e
forall e. Steps Id e -> Array DS Int e
fromSteps (Steps Id e -> Array DS Int e)
-> (Array r ix e -> Steps Id e) -> Array r ix e -> Array DS Int e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Steps Id e -> Steps Id e
forall (m :: * -> *) a. Monad m => Int -> Steps m a -> Steps m a
S.take (Sz1 -> Int
forall ix. Sz ix -> ix
unSz Sz1
n) (Steps Id e -> Steps Id e)
-> (Array r ix e -> Steps Id e) -> Array r ix e -> Steps Id e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Array r ix e -> Steps Id e
forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream
{-# INLINE takeS #-}
{-# DEPRECATED takeS "In favor of `stake`" #-}

-- | See `sdrop`.
--
-- @since 0.4.1
dropS :: Stream r ix e => Sz1 -> Array r ix e -> Array DS Ix1 e
dropS :: Sz1 -> Array r ix e -> Array DS Int e
dropS Sz1
n = Steps Id e -> Array DS Int e
forall e. Steps Id e -> Array DS Int e
fromSteps (Steps Id e -> Array DS Int e)
-> (Array r ix e -> Steps Id e) -> Array r ix e -> Array DS Int e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Steps Id e -> Steps Id e
forall (m :: * -> *) a. Monad m => Int -> Steps m a -> Steps m a
S.drop (Sz1 -> Int
forall ix. Sz ix -> ix
unSz Sz1
n) (Steps Id e -> Steps Id e)
-> (Array r ix e -> Steps Id e) -> Array r ix e -> Steps Id e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Array r ix e -> Steps Id e
forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream
{-# INLINE dropS #-}
{-# DEPRECATED dropS "In favor of `sdrop`" #-}

-- | See `sunfoldr`
--
-- @since 0.4.1
unfoldr :: (s -> Maybe (e, s)) -> s -> Vector DS e
unfoldr :: (s -> Maybe (e, s)) -> s -> Vector DS e
unfoldr = (s -> Maybe (e, s)) -> s -> Vector DS e
forall s e. (s -> Maybe (e, s)) -> s -> Vector DS e
sunfoldr
{-# INLINE unfoldr #-}
{-# DEPRECATED unfoldr "In favor of `sunfoldr`" #-}


-- | See `sunfoldrN`
--
-- @since 0.4.1
unfoldrN :: Sz1 -> (s -> Maybe (e, s)) -> s -> Vector DS e
unfoldrN :: Sz1 -> (s -> Maybe (e, s)) -> s -> Vector DS e
unfoldrN = Sz1 -> (s -> Maybe (e, s)) -> s -> Vector DS e
forall s e. Sz1 -> (s -> Maybe (e, s)) -> s -> Vector DS e
unfoldrN
{-# INLINE unfoldrN #-}
{-# DEPRECATED unfoldrN "In favor of `sunfoldrN`" #-}


-- | See `sfilterM`
--
-- @since 0.4.1
filterM :: (S.Stream r ix e, Applicative f) => (e -> f Bool) -> Array r ix e -> f (Vector DS e)
filterM :: (e -> f Bool) -> Array r ix e -> f (Vector DS e)
filterM e -> f Bool
f Array r ix e
arr = Steps Id e -> Vector DS e
forall e. Steps Id e -> Array DS Int e
DSArray (Steps Id e -> Vector DS e) -> f (Steps Id e) -> f (Vector DS e)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (e -> f Bool) -> Steps Id e -> f (Steps Id e)
forall (m :: * -> *) (f :: * -> *) e.
(Monad m, Applicative f) =>
(e -> f Bool) -> Steps Id e -> f (Steps m e)
S.filterA e -> f Bool
f (Array r ix e -> Steps Id e
forall r ix e. Stream r ix e => Array r ix e -> Steps Id e
S.toStream Array r ix e
arr)
{-# INLINE filterM #-}
{-# DEPRECATED filterM "In favor of `sfilterM`" #-}

-- | See `sfilter`
--
-- @since 0.4.1
filterS :: S.Stream r ix e => (e -> Bool) -> Array r ix e -> Array DS Ix1 e
filterS :: (e -> Bool) -> Array r ix e -> Array DS Int e
filterS = (e -> Bool) -> Array r ix e -> Array DS Int e
forall r ix e.
Stream r ix e =>
(e -> Bool) -> Array r ix e -> Vector DS e
sfilter
{-# INLINE filterS #-}
{-# DEPRECATED filterS "In favor of `sfilter`" #-}


-- | See `smapMaybe`
--
-- @since 0.4.1
mapMaybeS :: S.Stream r ix a => (a -> Maybe b) -> Array r ix a -> Vector DS b
mapMaybeS :: (a -> Maybe b) -> Array r ix a -> Vector DS b
mapMaybeS = (a -> Maybe b) -> Array r ix a -> Vector DS b
forall r ix a b.
Stream r ix a =>
(a -> Maybe b) -> Array r ix a -> Vector DS b
smapMaybe
{-# INLINE mapMaybeS #-}
{-# DEPRECATED mapMaybeS "In favor of `smapMaybe`" #-}

-- | See `scatMaybes`
--
-- @since 0.4.4
catMaybesS :: S.Stream r ix (Maybe a) => Array r ix (Maybe a) -> Vector DS a
catMaybesS :: Array r ix (Maybe a) -> Vector DS a
catMaybesS = Array r ix (Maybe a) -> Vector DS a
forall r ix a.
Stream r ix (Maybe a) =>
Array r ix (Maybe a) -> Vector DS a
scatMaybes
{-# INLINE catMaybesS #-}
{-# DEPRECATED catMaybesS "In favor of `scatMaybes`" #-}

-- | See `smapMaybeM`
--
-- @since 0.4.1
mapMaybeM ::
     (S.Stream r ix a, Applicative f) => (a -> f (Maybe b)) -> Array r ix a -> f (Vector DS b)
mapMaybeM :: (a -> f (Maybe b)) -> Array r ix a -> f (Vector DS b)
mapMaybeM = (a -> f (Maybe b)) -> Array r ix a -> f (Vector DS b)
forall r ix a (f :: * -> *) b.
(Stream r ix a, Applicative f) =>
(a -> f (Maybe b)) -> Array r ix a -> f (Vector DS b)
smapMaybeM
{-# INLINE mapMaybeM #-}
{-# DEPRECATED mapMaybeM "In favor of `smapMaybeM`" #-}

-- | See `traverseS`
--
-- @since 0.4.5
traverseS :: (S.Stream r ix a, Applicative f) => (a -> f b) -> Array r ix a -> f (Vector DS b)
traverseS :: (a -> f b) -> Array r ix a -> f (Vector DS b)
traverseS = (a -> f b) -> Array r ix a -> f (Vector DS b)
forall r ix a (f :: * -> *) b.
(Stream r ix a, Applicative f) =>
(a -> f b) -> Array r ix a -> f (Vector DS b)
straverse
{-# INLINE traverseS #-}
{-# DEPRECATED traverseS "In favor of `straverse`" #-}

-- | See `simapMaybe`
--
-- @since 0.4.1
imapMaybeS :: Source r ix a => (ix -> a -> Maybe b) -> Array r ix a -> Array DS Ix1 b
imapMaybeS :: (ix -> a -> Maybe b) -> Array r ix a -> Array DS Int b
imapMaybeS ix -> a -> Maybe b
f Array r ix a
arr =
  ((ix, a) -> Maybe b) -> Array D ix (ix, a) -> Array DS Int b
forall r ix a b.
Stream r ix a =>
(a -> Maybe b) -> Array r ix a -> Vector DS b
mapMaybeS ((ix -> a -> Maybe b) -> (ix, a) -> Maybe b
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry ix -> a -> Maybe b
f) (Array D ix (ix, a) -> Array DS Int b)
-> Array D ix (ix, a) -> Array DS Int b
forall a b. (a -> b) -> a -> b
$ D -> Comp -> Sz ix -> (ix -> (ix, a)) -> Array D ix (ix, a)
forall r ix e.
Construct r ix e =>
r -> Comp -> Sz ix -> (ix -> e) -> Array r ix e
A.makeArrayR D
D (Array r ix a -> Comp
forall r ix e. Load r ix e => Array r ix e -> Comp
getComp Array r ix a
arr) (Array r ix a -> Sz ix
forall r ix e. Load r ix e => Array r ix e -> Sz ix
size Array r ix a
arr) ((ix -> (ix, a)) -> Array D ix (ix, a))
-> (ix -> (ix, a)) -> Array D ix (ix, a)
forall a b. (a -> b) -> a -> b
$ \ix
ix -> (ix
ix, Array r ix a -> ix -> a
forall r ix e. Source r ix e => Array r ix e -> ix -> e
unsafeIndex Array r ix a
arr ix
ix)
{-# INLINE imapMaybeS #-}
{-# DEPRECATED imapMaybeS "In favor of `simapMaybe`" #-}

-- | See `simapMaybeM`
--
-- @since 0.4.1
imapMaybeM ::
     (Source r ix a, Applicative f) => (ix -> a -> f (Maybe b)) -> Array r ix a -> f (Array DS Ix1 b)
imapMaybeM :: (ix -> a -> f (Maybe b)) -> Array r ix a -> f (Array DS Int b)
imapMaybeM ix -> a -> f (Maybe b)
f Array r ix a
arr =
  ((ix, a) -> f (Maybe b))
-> Array D ix (ix, a) -> f (Array DS Int b)
forall r ix a (f :: * -> *) b.
(Stream r ix a, Applicative f) =>
(a -> f (Maybe b)) -> Array r ix a -> f (Vector DS b)
mapMaybeM ((ix -> a -> f (Maybe b)) -> (ix, a) -> f (Maybe b)
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry ix -> a -> f (Maybe b)
f) (Array D ix (ix, a) -> f (Array DS Int b))
-> Array D ix (ix, a) -> f (Array DS Int b)
forall a b. (a -> b) -> a -> b
$ D -> Comp -> Sz ix -> (ix -> (ix, a)) -> Array D ix (ix, a)
forall r ix e.
Construct r ix e =>
r -> Comp -> Sz ix -> (ix -> e) -> Array r ix e
A.makeArrayR D
D (Array r ix a -> Comp
forall r ix e. Load r ix e => Array r ix e -> Comp
getComp Array r ix a
arr) (Array r ix a -> Sz ix
forall r ix e. Load r ix e => Array r ix e -> Sz ix
size Array r ix a
arr) ((ix -> (ix, a)) -> Array D ix (ix, a))
-> (ix -> (ix, a)) -> Array D ix (ix, a)
forall a b. (a -> b) -> a -> b
$ \ix
ix -> (ix
ix, Array r ix a -> ix -> a
forall r ix e. Source r ix e => Array r ix e -> ix -> e
unsafeIndex Array r ix a
arr ix
ix)
{-# INLINE imapMaybeM #-}
{-# DEPRECATED imapMaybeM "In favor of `simapMaybeM`" #-}

-- | Similar to `filterS`, but map with an index aware function.
--
-- @since 0.4.1
ifilterS :: Source r ix a => (ix -> a -> Bool) -> Array r ix a -> Array DS Ix1 a
ifilterS :: (ix -> a -> Bool) -> Array r ix a -> Array DS Int a
ifilterS ix -> a -> Bool
f =
  (ix -> a -> Maybe a) -> Array r ix a -> Array DS Int a
forall r ix a b.
Source r ix a =>
(ix -> a -> Maybe b) -> Array r ix a -> Array DS Int b
imapMaybeS ((ix -> a -> Maybe a) -> Array r ix a -> Array DS Int a)
-> (ix -> a -> Maybe a) -> Array r ix a -> Array DS Int a
forall a b. (a -> b) -> a -> b
$ \ix
ix a
e ->
    if ix -> a -> Bool
f ix
ix a
e
      then a -> Maybe a
forall a. a -> Maybe a
Just a
e
      else Maybe a
forall a. Maybe a
Nothing
{-# INLINE ifilterS #-}
{-# DEPRECATED ifilterS "In favor of `sifilter`" #-}


-- | Similar to `filterM`, but map with an index aware function.
--
-- @since 0.4.1
ifilterM ::
     (Source r ix a, Applicative f) => (ix -> a -> f Bool) -> Array r ix a -> f (Array DS Ix1 a)
ifilterM :: (ix -> a -> f Bool) -> Array r ix a -> f (Array DS Int a)
ifilterM ix -> a -> f Bool
f =
  (ix -> a -> f (Maybe a)) -> Array r ix a -> f (Array DS Int a)
forall r ix a (f :: * -> *) b.
(Source r ix a, Applicative f) =>
(ix -> a -> f (Maybe b)) -> Array r ix a -> f (Array DS Int b)
imapMaybeM ((ix -> a -> f (Maybe a)) -> Array r ix a -> f (Array DS Int a))
-> (ix -> a -> f (Maybe a)) -> Array r ix a -> f (Array DS Int a)
forall a b. (a -> b) -> a -> b
$ \ix
ix a
e ->
    (\Bool
p ->
       if Bool
p
         then a -> Maybe a
forall a. a -> Maybe a
Just a
e
         else Maybe a
forall a. Maybe a
Nothing) (Bool -> Maybe a) -> f Bool -> f (Maybe a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
    ix -> a -> f Bool
f ix
ix a
e
{-# INLINE ifilterM #-}
{-# DEPRECATED ifilterM "In favor of `sifilterM`" #-}