Split off StreamingHelp module
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
module StreamingHelp
|
||||
( minStreamOn
|
||||
, sortStreamOn
|
||||
, StreamOf
|
||||
, module Streaming
|
||||
) where
|
||||
import Streaming
|
||||
import qualified Streaming.Prelude as S
|
||||
import qualified Control.Foldl as L
|
||||
import Data.Function (on)
|
||||
|
||||
type StreamOf a = Stream (Of a) Identity ()
|
||||
|
||||
minStreamOn :: Ord a => (b -> a) -> StreamOf b -> Maybe b
|
||||
{-# INLINE minStreamOn #-}
|
||||
minStreamOn f = runIdentity
|
||||
. L.purely S.fold_ (L.minimumBy (compare `on` f))
|
||||
|
||||
-- this hopefully also nub the stream in most cases
|
||||
--orderStreamOn :: Ord b => (a -> b) -> Stream (Of a) Identity () -> Identity (Of (M.Map b a) ())
|
||||
sortStreamOn :: Ord a => (b -> a) -> StreamOf b -> Stream (Of b) Identity ()
|
||||
{-# INLINE sortStreamOn #-}
|
||||
sortStreamOn f = S.each . runIdentity . L.purely S.fold_ L.map . S.map g
|
||||
where
|
||||
g x = (f x,x)
|
||||
Reference in New Issue
Block a user