#include "fusion-phases.h"
module Data.Array.Parallel.Stream.Flat.Search (
findS, findIndexS
) where
import Data.Array.Parallel.Stream.Flat.Stream
findS :: (a -> Bool) -> Stream a -> Maybe a
findS p (Stream next s _) = go s
where
go s = case next s of
Yield x s' | p x -> Just x
| otherwise -> go s'
Skip s' -> go s'
Done -> Nothing
findIndexS :: (a -> Bool) -> Stream a -> Maybe Int
findIndexS p (Stream next s _) = go 0 s
where
go i s = case next s of
Yield x s' | p x -> Just i
| otherwise -> go (i+1) s'
Skip s' -> go i s'
Done -> Nothing