Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,19 @@ trait EnhancedFold[F[_], S, E] {
}
}

/**
* Returns a fold that discards events for which f returns false
*/
final def filter(f: (S, E) => Boolean)(implicit F: Applicative[F]): EnhancedFold[F, S, E] =
(extras, state0, event) =>
state0 match {
case Some(state) => if (f(state, event)) apply(extras, state0, event) else F.pure(state0)
case None => apply(extras, state0, event)
}

/**
* Similar to `filter`
*/
final def filterM(f: (S, E) => F[Boolean])(implicit F: Monad[F]): EnhancedFold[F, S, E] =
(extras, state0, event) =>
state0 match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import cats.Functor
import cats.Monad
import cats.syntax.all._

/** Reads a state and effectfully produces a new one.
/**
* @see [[com.evolutiongaming.kafka.flow.EnhancedFold]]
*
* Reads a state and effectfully produces a new one.
*
* Roughly speaking it is `Kleisli[F, (S, A), S]` with the main additional
* requirement that input and output types are not independent (because `S`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import cats.Functor
import cats.Monad
import cats.syntax.all._

/** Convenience methods for using `Fold` with optional state */
/**
* @see [[com.evolutiongaming.kafka.flow.EnhancedFold]]
*
* Convenience methods for using `Fold` with optional state
* */
final case class FoldOption[F[_], S, A](value: Fold[F, Option[S], A]) {

/** Alias for `run` */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import cats.syntax.all._
import com.evolutiongaming.kafka.flow.effect.CatsEffectMtlInstances._
import com.evolutiongaming.kafka.flow.persistence.Persistence

/** Applies records to a state stored inside and informs the listeners about the changes */
/**
* Applies records to a state stored inside and performs the necessary updates,
* for example, it can persist the state and remove it from memory.
*/
trait FoldToState[F[_], E] {

def apply(records: NonEmptyList[E]): F[Unit]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import com.evolutiongaming.kafka.flow.persistence.Persistence
import com.evolutiongaming.kafka.flow.registry.EntityRegistry
import com.evolutiongaming.kafka.flow.timer.{TimerContext, TimerFlowOf}

/**
* Factory of KeyFlows
*/
trait KeyFlowOf[F[_], S, A] {

def apply(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import com.evolutiongaming.kafka.journal.ConsRecord
import com.evolutiongaming.skafka.TopicPartition
import com.evolutiongaming.sstream.Stream

/**
* Factory of KeyStates
*/
trait KeyStateOf[F[_]] { self =>

/** Creates or restores a state for a single key */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import com.evolutiongaming.kafka.flow.PartitionFlow.FilterRecord
import com.evolutiongaming.kafka.flow.kafka.ScheduleCommit
import com.evolutiongaming.skafka.{Offset, TopicPartition}

/**
* Factory of PartitionFlows
*/
trait PartitionFlowOf[F[_]] {

/** Creates partition record handler for assigned partition */
Expand Down
5 changes: 5 additions & 0 deletions core/src/main/scala/com/evolutiongaming/kafka/flow/Tick.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import cats.Applicative
import cats.syntax.all._
import cats.Functor

/**
* Updates an aggregate. Tick is similar to [[com.evolutiongaming.kafka.flow.EnhancedFold]],
* but gets triggered by timers instead of incoming events.
* For example, you may want to regularly delete aggregates that haven't been updated for N minutes.
*/
case class Tick[F[_], S](run: S => F[S]) {

/** Alias for `run` */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package com.evolutiongaming.kafka.flow
import cats.Applicative
import cats.Functor

/**
* Similar to [[com.evolutiongaming.kafka.flow.Tick]]
*/
case class TickOption[F[_], S](value: Tick[F, Option[S]]) {

/** Alias for `value.run` */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import com.evolutiongaming.catshelper.{LogOf, Runtime}
import com.evolutiongaming.kafka.flow.kafka.Consumer
import com.evolutiongaming.skafka.Topic

/**
* Factory of TopicFlows
*/
trait TopicFlowOf[F[_]] {

def apply(consumer: Consumer[F], topic: Topic): Resource[F, TopicFlow[F]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import com.evolutiongaming.kafka.flow.persistence.FlushBuffers

import scala.concurrent.duration._

/**
* Factory of TimerFlows
*/
trait TimerFlowOf[F[_]] {

def apply(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import cats.effect.Sync
import cats.syntax.all._
import com.evolutiongaming.catshelper.LogOf

/**
* Factory of TimerContexts
*/
trait TimersOf[F[_], K] {

def apply(key: K, createdAt: Timestamp): F[TimerContext[F]]
Expand Down