Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@iravid
Copy link
Member

@iravid iravid commented Sep 14, 2019

Resolves: #1671
Resolves: #1673

@vasilmkd could you have a look?

): ZSink[Any, Nothing, A, A, S] =
new SinkPure[Nothing, A, A, S] {
type State = (S, Long, Boolean, Chunk[A])
import internal.FoldWeightedState
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are starting to use ZSink.internal for complex states, it makes sense to restrict the old imports to only the needed types. Just a mental note.

* of type `S`, until `max` worth of elements (determined by the `costFn`)
* have been folded.
*
* @note In case
Copy link
Contributor

@vasilmkd vasilmkd Sep 14, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing scaladoc? Same with foldWeighted.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, yes.

* of type `S`, until `max` worth of elements (determined by the `costFn`) have
* been folded.
*/
final def foldWeightedDecomposeM[R, R1 <: R, E, E1 >: E, A, S](
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should document the decompose function better.

*/
final def foldWeightedDecompose[A, S](
z: S
)(costFn: A => Long, max: Long, decompose: A => Chunk[A] = Chunk.single[A](_))(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scala 2.11 has trouble with this line.

@vasilmkd
Copy link
Contributor

Minor documentation comments. Have a written approval. 😄

init <- sink.initial.toManaged_
sinkStateRef <- Ref.make[(sink.State, Boolean)]((init, false)).toManaged_
done <- Ref.make(false).toManaged_
sink <- managedSink.map(_.mapError(Some(_)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice.

@iravid iravid merged commit 6f02314 into zio:master Sep 14, 2019
fsvehla pushed a commit to fsvehla/zio that referenced this pull request Sep 21, 2019
…uce (zio#1675)

* Add ZSink.foldWeightedDecompose/M and fix leftover handling in transduce

* 2.11 fixes

* Improve docs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor ZStream#transduce to not use Sink#stepChunk Sink.foldWeighted can get stuck on a single element larger than max

2 participants