Skip to content

Commit

Permalink
Merge pull request #410 from catostrophe/sbt-update
Browse files Browse the repository at this point in the history
Update sbt, sbt-rewarn, scalafmt
  • Loading branch information
Odomontois authored Oct 7, 2020
2 parents 44db127 + 1ad5dbc commit 45d3043
Show file tree
Hide file tree
Showing 31 changed files with 125 additions and 247 deletions.
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ binPack.parentConstructors = true
maxColumn = 120
includeCurlyBraceInSelectChains = false
align.preset = most
version = "2.7.3"
version = "2.7.4"
trailingCommas = preserve
newlines.penalizeSingleSelectMultiArgList = false
newlines.alwaysBeforeMultilineDef = false
36 changes: 12 additions & 24 deletions concurrent/src/main/scala/tofu/concurrent/Agent.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,39 @@ import tofu.Fire
import tofu.syntax.fire._
import tofu.syntax.monadic._

/**
* A mutable atomic reference augmented with effectful operations.
/** A mutable atomic reference augmented with effectful operations.
* Can be thought as TF version of zio.RefM
*/
trait Agent[F[_], A] {

/**
* Reads the value from the `Agent`.
/** Reads the value from the `Agent`.
*
* @return `F[A]` value from `Agent`
*/
def get: F[A]

/**
* Update value with effectful transformation, wait for the new result
/** Update value with effectful transformation, wait for the new result
*
* @param f function to atomically modify the `Agent`
* @return `F[A]` modified value of `Agent`
*/
def updateM(f: A => F[A]): F[A]

/**
* Enqueue transformation, return immediately.
/** Enqueue transformation, return immediately.
*
* @param f function to atomically modify the `Agent`
* @return `F[Unit]`
*/
def fireUpdateM(f: A => F[A]): F[Unit]

/**
* Modify value with effectful transformation, calculating result.
/** Modify value with effectful transformation, calculating result.
*
* @param f function which computes a return value for the modification
* @return `F[B]` modified value of `Agent`
*/
def modifyM[B](f: A => F[(B, A)]): F[B]

/**
* Modifies the `Agent` with the specified partial function.
/** Modifies the `Agent` with the specified partial function.
* If function is undefined on the current value it doesn't change it.
*
* @param f partial function to modify the `Agent`
Expand All @@ -53,8 +47,7 @@ trait Agent[F[_], A] {

// NOTE: B => F[B] looks like tagless encoding of F[Option[B]]
// we are choosing towards ZIO to simplify adoption
/**
* Modifies the `Agent` with the specified partial function, which computes
/** Modifies the `Agent` with the specified partial function, which computes
* a return value for the modification if the function is defined in the current value.
* Otherwise it returns a default value.
*
Expand All @@ -68,8 +61,7 @@ trait Agent[F[_], A] {
object Agent {
// private[this] val representableAny: RepresentableK[Agent[*[_], Any]] = derived.genRepresentableK[Agent[*[_], Any]]

/**
* Default implementation of [[tofu.concurrent.Agent]]
/** Default implementation of [[tofu.concurrent.Agent]]
* that consists of [[cats.effect.concurrent.Ref]] and [[cats.effect.concurrent.Semaphore]]
*/
final case class SemRef[F[_]: Monad: Fire, A](ref: Ref[F, A], sem: Semaphore[F]) extends Agent[F, A] {
Expand All @@ -85,25 +77,22 @@ object Agent {
}
}

/**
* A creator of [[tofu.concurrent.Agent]] that supports effectful construction.
/** A creator of [[tofu.concurrent.Agent]] that supports effectful construction.
*
* @tparam I effect for creation of agent
* @tparam F effect on which agent will be run
*/
trait MakeAgent[I[_], F[_]] {

/**
* Creates instance of [[tofu.concurrent.Agent]] with given value
/** Creates instance of [[tofu.concurrent.Agent]] with given value
*
* @param a value to be contained in `Agent`
* @return `I[Agent[F, A]]`
*/
def agentOf[A](a: A): I[Agent[F, A]]
}

/**
* A helper for creating instances of [[tofu.concurrent.Agent]] that use same effect during construction and work.
/** A helper for creating instances of [[tofu.concurrent.Agent]] that use same effect during construction and work.
* If you want to use different effect to construct `Agent` use [[tofu.concurrent.MakeAgent]]
*
* Sample usage:
Expand All @@ -128,8 +117,7 @@ object Agents {
def apply[F[_]](implicit agents: Agents[F]): MakeAgent.Applier[F, F] = new MakeAgent.Applier[F, F](agents)
}

/**
* A helper for creating instances of [[tofu.concurrent.Agent]] that use different effects during construction and work.
/** A helper for creating instances of [[tofu.concurrent.Agent]] that use different effects during construction and work.
* If you want to use same effect to construct and run `Agent` use [[tofu.concurrent.Agents]]
*
* Sample usage:
Expand Down
15 changes: 5 additions & 10 deletions concurrent/src/main/scala/tofu/concurrent/Atom.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,14 @@ import tofu.data.calc.CalcM
/** a middleground between cats.concurrent.Ref and zio.Ref */
trait Atom[+F[_], A] {

/**
* Obtains the current value.
/** Obtains the current value.
*
* Since `Ref` is always guaranteed to have a value, the returned action
* completes immediately after being bound.
*/
def get: F[A]

/**
* Sets the current value to `a`.Agent
/** Sets the current value to `a`.Agent
*
* The returned action completes after the reference has been successfully set.
*
Expand All @@ -32,13 +30,11 @@ trait Atom[+F[_], A] {
*/
def set(a: A): F[Unit]

/**
* Replaces the current value with `a`, returning the previous value.
/** Replaces the current value with `a`, returning the previous value.
*/
def getAndSet(a: A): F[A]

/**
* Modifies the current value using the supplied update function. If another modification
/** Modifies the current value using the supplied update function. If another modification
* occurs between the time the current value is read and subsequently updated, the modification
* is retried using the new value. Hence, `f` may be invoked multiple times.
*
Expand All @@ -47,8 +43,7 @@ trait Atom[+F[_], A] {
*/
def update(f: A => A): F[Unit]

/**
* Like `tryModify` but does not complete until the update has been successfully made.
/** Like `tryModify` but does not complete until the update has been successfully made.
*/
def modify[B](f: A => (A, B)): F[B]
}
Expand Down
12 changes: 4 additions & 8 deletions concurrent/src/main/scala/tofu/concurrent/Gatekeeper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,23 @@ import tofu.syntax.monadic._
/** Semaphore-like structure */
trait Gatekeeper[F[_], A] {

/**
* Returns the number of permits currently available.
/** Returns the number of permits currently available.
* May be out of date the instant after it is retrieved.
*/
def available: F[A]

/**
* Obtains a snapshot of the currently taken.
/** Obtains a snapshot of the currently taken.
*
* Like [[available]] when permits are available but returns the number of permits
* callers are waiting for when there are no permits available.
*/
def taken: F[A]

/**
* Returns an effect that acquires a permit, runs the supplied effect, and then releases the permit.
/** Returns an effect that acquires a permit, runs the supplied effect, and then releases the permit.
*/
def withPermit[B](t: F[B]): F[B]

/**
* Returns an effect that acquires a permit, runs the supplied effect, and then releases the permit.
/** Returns an effect that acquires a permit, runs the supplied effect, and then releases the permit.
*/
def withPermitN[B](take: A)(t: F[B]): F[B]
}
Expand Down
15 changes: 5 additions & 10 deletions concurrent/src/main/scala/tofu/concurrent/MakeRef.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ package tofu.concurrent
import cats.effect.Sync
import cats.effect.concurrent.Ref

/**
* Effectful making and initialization for `Ref`.
/** Effectful making and initialization for `Ref`.
* A 'Ref' instance will be initialized in the `I[_]' effect.
* 'F[_]' is the effect in which 'Ref' will work.
*/
Expand All @@ -14,8 +13,7 @@ trait MakeRef[I[_], F[_]] {

object Refs {

/**
* Creates a `MakeRef[F,F]` when both effect constructors are the same.
/** Creates a `MakeRef[F,F]` when both effect constructors are the same.
*
* @param agents an given instance of `Refs[F]' (type alias for `MakeRef[F, F]`)
* @return instace of [[Applier[F, F]]]
Expand All @@ -25,8 +23,7 @@ object Refs {

object MakeRef {

/**
* Makes a `Ref` instance
/** Makes a `Ref` instance
*
* Uses the
* [[https://typelevel.org/cats/guidelines.html#partially-applied-type-params Partially-Applied Type]]
Expand All @@ -43,8 +40,7 @@ object MakeRef {

final class Applier[I[_], F[_]](private val makeRef: MakeRef[I, F]) extends AnyVal {

/**
* Makes a Ref initialized to the supplied value.
/** Makes a Ref initialized to the supplied value.
* Like [[Ref.of]] but initializes state using another effect constructor.
*
* @see [[MakeRef.refOf]]
Expand All @@ -53,8 +49,7 @@ object MakeRef {
def of[A](a: A): I[Ref[F, A]] = makeRef.refOf(a)
}

/**
* Give an instance of `MakeRef[I, F]` to making `Ref` for effect with `Sync` type class.
/** Give an instance of `MakeRef[I, F]` to making `Ref` for effect with `Sync` type class.
*
* @return instance of [[MakeRef[I,F]]]
*/
Expand Down
12 changes: 4 additions & 8 deletions concurrent/src/main/scala/tofu/concurrent/QVar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,15 @@ import scala.annotation.nowarn
/** a middleground between cats.concurrent.MVar and zio.Queue.bounded(1) */
trait QVar[+F[_], A] {

/**
* Returns `true` if the `MVar` is empty and can receive a `put`, or
/** Returns `true` if the `MVar` is empty and can receive a `put`, or
* `false` otherwise.
*
* Note that due to concurrent tasks, logic built in terms of `isEmpty`
* is problematic.
*/
def isEmpty: F[Boolean]

/**
* Fills the `MVar` if it is empty, or blocks (asynchronously)
/** Fills the `MVar` if it is empty, or blocks (asynchronously)
* if the `MVar` is full, until the given value is next in
* line to be consumed on [[take]].
*
Expand All @@ -35,8 +33,7 @@ trait QVar[+F[_], A] {
*/
def put(a: A): F[Unit]

/**
* Empties the `MVar` if full, returning the contained value,
/** Empties the `MVar` if full, returning the contained value,
* or blocks (asynchronously) until a value is available.
*
* This operation is atomic.
Expand All @@ -46,8 +43,7 @@ trait QVar[+F[_], A] {
*/
def take: F[A]

/**
* Tries reading the current value, or blocks (asynchronously)
/** Tries reading the current value, or blocks (asynchronously)
* until there is a value available.
*
* This operation is atomic.
Expand Down
Loading

0 comments on commit 45d3043

Please sign in to comment.