Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple issue resolution #2891

Merged
merged 3 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions core/src/Streamly/Internal/Data/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ where
#include "deprecation.h"
#include "assert.hs"

import Control.Monad (when)
import Data.Bifunctor (first)
import Fusion.Plugin.Types (Fuse(..))
import Streamly.Internal.Data.Fold.Type (Fold(..))
Expand Down Expand Up @@ -676,11 +675,15 @@ takeBetween low high (Fold fstep finitial _ ffinal) =
then IDone b
else IError (foldErr i1)

initial = do
when (low >= 0 && high >= 0 && low > high)
$ error invalidRange

finitial >>= inext (-1)
-- In the case of Identity monad
-- @
-- when True (error invalidRange)
-- @
-- does not evaluate the @error invalidRange@ due to which no error occurs.
initial =
if low >= 0 && high >= 0 && low > high
then error invalidRange
else finitial >>= inext (-1)

-- Keep the impl same as inext
{-# INLINE snext #-}
Expand Down
13 changes: 9 additions & 4 deletions core/src/Streamly/Internal/Data/StreamK.hs
Original file line number Diff line number Diff line change
Expand Up @@ -117,19 +117,23 @@ module Streamly.Internal.Data.StreamK
, the

-- ** Transforming Inner Monad
, hoist
, morphInner

-- * Exceptions
, handle

-- * Resource Management
, bracketIO

-- * Deprecated
, hoist
)
where

#include "ArrayMacros.h"
#include "inline.hs"
#include "assert.hs"
#include "deprecation.h"

import Control.Exception (mask_, Exception)
import Control.Monad (void, join)
Expand Down Expand Up @@ -687,16 +691,17 @@ toList :: Monad m => StreamK m a -> m [a]
toList = foldr (:) []

-- Based on suggestions by David Feuer and Pranay Sashank
{-# INLINE hoist #-}
hoist :: (Monad m, Monad n)
{-# INLINE morphInner #-}
morphInner, hoist :: (Monad m, Monad n)
=> (forall x. m x -> n x) -> StreamK m a -> StreamK n a
hoist f str =
morphInner f str =
mkStream $ \st yld sng stp ->
let single = return . sng
yieldk a s = return $ yld a (hoist f s)
stop = return stp
state = adaptState st
in join . f $ foldStreamShared state yieldk single stop str
RENAME(hoist,morphInner)

-------------------------------------------------------------------------------
-- Transformation by folding (Scans)
Expand Down
Loading
Loading