packages feed

effectful-streamly-0.1.0.0: README.md

# effectful-streamly

Concurrent [Streamly](https://hackage.haskell.org/package/streamly) streams
in [Effectful](https://hackage.haskell.org/package/effectful).

Streamly evaluates concurrent streams in worker threads and reaches the
base monad through `MonadBaseControl`. `Eff` implements it with the
unlifting strategy of its `IOE` context, whose default refuses to run in
another thread: `parList`, `parMapM` and the other concurrent combinators
fail in `Eff` unless that strategy is changed.

This package changes it for you:

- `Effectful.Streamly.Stream` replaces `Streamly.Data.Stream.Prelude`.
  The serial API is re-exported as it is; every concurrent combinator works
  in `Eff`, whatever the strategy of the code that consumes the stream.
- `Effectful.Streamly` holds the wrapper it is built on, `concurrently`,
  for streams built some other way.

```haskell
import Effectful (Eff, IOE, liftIO, (:>))
import Effectful.Streamly.Stream (fromList, parMapM, toList)

lengths :: IOE :> es => [FilePath] -> Eff es [Int]
lengths paths = toList (parMapM id (fmap length . liftIO . readFile) (fromList paths))
```

## Effects in worker threads

Each worker gets its own copy of the environment, as in any thread that
Effectful forks:

- effects with local state, such as `Effectful.State.Static.Local`, are not
  shared: a change made by a worker stays in that worker;
- shared effects, such as `Effectful.State.Static.Shared`, are seen by
  everyone;
- an `Error` thrown in a worker reaches the handler of the consumer, and so
  does an exception.

## Known defects of streamly 0.11.1

`takeInterval` always yields an empty stream, and `dropInterval` drops
nothing when the stream yields at once
([streamly#3271](https://github.com/composewell/streamly/issues/3271)). The
wrappers keep that behaviour; a test records it.

Tested with GHC 9.8.4, 9.10.3 and 9.12.4, effectful 2.7.1, streamly 0.11.1.

## License

BSD-3-Clause. See [LICENSE](LICENSE).