<commit_before>{-# LANGUAGE ExistentialQuantification, BangPatterns, CPP #-}

#include "phases.h"

module Data.Vector.Stream (
  Step(..), Stream(..),

  empty, singleton, replicate, (++),
  map, filter, zipWith,
  foldr, foldl, foldl',
  mapM_, foldM
) where

import Prelude hiding ( replicate, (++), map, filter, zipWith,
                        foldr, foldl,
                        mapM_ )

data Step s a = Yield a s
              | Skip    s
              | Done

data Stream a = forall s. Stream (s -> Step s a) s Int

empty :: Stream a
{-# INLINE_STREAM empty #-}
empty = Stream (const Done) () 0

singleton :: a -> Stream a
{-# INLINE_STREAM singleton #-}
singleton x = Stream step True 1
  where
    {-# INLINE step #-}
    step True  = Yield x False
    step False = Done<commit_msg>Stream.bound and Stream.unfold<commit_after>{-# LANGUAGE ExistentialQuantification, BangPatterns, CPP #-}

#include "phases.h"

module Data.Vector.Stream (
  Step(..), Stream(..),

  bound, unfold,
  empty, singleton, replicate, (++),
  map, filter, zipWith,
  foldr, foldl, foldl',
  mapM_, foldM
) where

import Prelude hiding ( replicate, (++), map, filter, zipWith,
                        foldr, foldl,
                        mapM_ )

data Step s a = Yield a s
              | Skip    s
              | Done

data Stream a = forall s. Stream (s -> Step s a) s Int

bound :: Stream a -> Int
{-# INLINE bound #-}
bound (Stream _ _ n) = n

unfold :: (s -> Maybe (a, s)) -> s -> Int -> Stream a
{-# INLINE_STREAM unfold #-}
unfold f s n = Stream step s n
  where
    {-# INLINE step #-}
    step s = case f s of
               Just (x, s') -> Yield x s'
               Nothing      -> Done

empty :: Stream a
{-# INLINE_STREAM empty #-}
empty = Stream (const Done) () 0

singleton :: a -> Stream a
{-# INLINE_STREAM singleton #-}
singleton x = Stream step True 1
  where
    {-# INLINE step #-}
    step True  = Yield x False
    step False = Done
{'fraction_non_alphanumeric': 0.13027806385169927, 'fraction_numerical': 0.0020597322348094747, 'mean_word_length': 2.1288244766505637, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7208855', 'n_tokens_mistral': 674, 'n_tokens_neox': 643, 'n_words': 225}