trait Sink[F[_], A] {
def apply(a: A): F[Unit]
}
class ListingProcessor[F[_]: Monad](transform: RawListing => FullListing,
save: Sink[F, Seq[FullListing]]) {
def process(listings: Seq[RawListing]): F[Unit] = {
val fullListings = listings.map(transform)
// ...logic, etc
save(fullListings)
}
}
val outputListing: FullListing = //...
val inputListing: RawListing = //...
val save = new MemorySink[ListingResults] // MemorySink[A] extends Sink[Id,A] now
val processor = new ListingProcessor[Id](_ => Some(outputListing), save)
processor.processListing(Seq(inputListing))
save.last should beSome(Seq(outputListing))
trait Sink[A] {
def apply(a: A): Async[Unit]
final def contraMap[B](f: B => A): Sink[B] =
b => apply(f(b))
}
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
alert("Blah"); |
OlderNewer