Uploaded image for project: 'Flink'
  1. Flink
  2. FLINK-9221

Add method SinkFunction[A]#contramap[B](f: B => A): SinkFunction[B]

    XMLWordPrintableJSON

Details

    Description

      Just like it is very useful to use `DataStream[T]` as a sort of Functor or Monad with `map`/`flatMap`/`filter` methods, it would be extremely handy to have a `SinkFunction[A]#contramap[B](f: B => A): SinkFunction[B]` on `SinkFunctions`, so that you can reuse existing complex sink functions, but with a different input type. For example:

      val bucketingStringSink: SinkFunction[String] = 
        new BucketingSink[String]("...")
          .setBucketer(new DateTimeBucketer("yyyy-MM-dd-HHmm")
      
      val bucketingIntListSink: SinkFunction[List[Int]] =
        bucketingStringSink.contramap[List[Int]](_.mkString(","))
      

      For some more formal motivation behind this, https://typelevel.org/cats/typeclasses/contravariant.html is definitely a great place to start!

      Attachments

        Activity

          People

            yanghua vinoyang
            joshlemer Josh Lemer
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated: