streamly icon indicating copy to clipboard operation
streamly copied to clipboard

Write init and tail as stream transformations

Open harendra-kumar opened this issue 3 years ago • 1 comments

init :: Monad m => Stream m a -> Stream m a
tail :: Monad m => Stream m a -> Stream m a

harendra-kumar avatar Jun 10 '22 08:06 harendra-kumar

As a stream transformation tail is just drop 1 except that tail errors out on empty srteam whereas drop does not.

We can generalize tail and init to drop and dropEnd. To imitate the tail and init behavior we may need dropExact and dropEndExact variants that error out if less than specified elements are dropped.

Also, once we have composable Scan type, we can write these as scans instead of stream specific implementations.

harendra-kumar avatar Aug 03 '22 17:08 harendra-kumar