All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.arainko.ducktape.internal.Accumulator.scala Maven / Gradle / Ivy

There is a newer version: 0.2.5
Show newest version
package io.github.arainko.ducktape.internal

import scala.collection.mutable.Builder

private[ducktape] opaque type Accumulator[A] = Builder[A, List[A]]

private[ducktape] object Accumulator {
  def use[A]: [B <: Tuple] => (f: Accumulator[A] ?=> B) => List[A] *: B =
    [B <: Tuple] =>
      (f: Accumulator[A] ?=> B) => {
        val builder = List.newBuilder[A]
        val result = f(using builder)
        builder.result() *: result
    }

  def append[A](value: A)(using acc: Accumulator[A]): A = {
    acc.addOne(value)
    value
  }

  def appendAll[A, B <: Iterable[A]](values: B)(using acc: Accumulator[A]): B = {
    acc.addAll(values)
    values
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy