streaming-nonempty: Add support for non empty streams to Streaming lib

[ bsd3, library, streaming ] [ Propose Tags ]

Please see the README on GitHub at https://gitlab.com/paolo.veronelli/streaming-nonempty/-/blob/master/README.md


[Skip to Readme]
Versions [RSS] [faq] 0.1.0.0, 0.1.0.1
Change log ChangeLog.md
Dependencies base (>=4.7 && <5), streaming [details]
License BSD-3-Clause
Copyright 2021 Paolo Veronelli
Author Paolo Veronelli
Maintainer paolo.veronelli@gmail.com
Category Streaming
Source repo head: git clone https://gitlab.com/paolo.veronelli/streaming-nonempty
Uploaded by PaoloVeronelli at 2021-09-08T17:17:29Z
Distributions NixOS:0.1.0.1
Downloads 128 total (5 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Hackage Matrix CI
Docs available [build log]
Last success reported on 2021-09-08 [all 1 reports]

Modules

[Index] [Quick Jump]

Downloads

Maintainer's Corner

For package maintainers and hackage trustees

Candidates


Readme for streaming-nonempty-0.1.0.1

[back to package description]

streaming-nonempty

A correct groupBy function is expected to produce only non-empty groups, which means we should be able to fold them up with only Semigroup constraint on the values. This is not the case for Data.List.groupBy as well for the Streaming lib counterpart.

This package export a groupBy function that produce f (Stream f m a) groups which are then guaranteed to have the functorial layer.

The NEStream (Of a) m r newtype is supporting sconcat which means we can define


groupSemigroupBy :: (Semigroup a, Monad m) => (a -> a -> Bool) -> Stream (Of a) m r -> Stream (Of a) m r
groupSemigroupBy f = S.mapped sconcat . groupBy f

with expected behavior to collapse groups using semigroup composition

In contrast using the standard groupBy we are stuck with


groupMonoidBy :: (Monoid a, Monad m) => (a -> a -> Bool) -> Stream (Of a) m r -> Stream (Of a) m r
groupMonoidBy f = S.mapped mconcat . groupBy f

It would be legit to use an sconcatUnsafe that would panic on empty streams because we know groups are not empty.