Skip to content

Instantly share code, notes, and snippets.

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))
}
@wjlow
wjlow / randomjs.js
Created September 3, 2019 01:19
Some random JS
alert("Blah");