scalding

Is there a way in Scalding Type Safe API to mapWithValue with two or more ValuePipes?


Using Scalding, Type Safe API, this code works, where dictForKeys and dictForValues are both ValuePipe[Map[String,String]]:

SomeKeyValueTypedPipe
  .mapWithValue(dictForKeys) { case ((key, value), dictForKeys) =>
       (dictForKeys.get.getOrElse(key, key), value) }
  .mapWithValue(dictForValues) { case ((key, value), dictForValues) =>
       (key, dictForValues.get.getOrElse(value, value)) }

I was just wondering whether there's a more compact way of writing this, i.e. use only 1 mapWithValue step with 2 separate ValuePipes.


Solution

  • You could create a ValuePipe of a tuple of Maps, like ValuePipe[(Map[String, String], Map[String, String])], and then use it like so:

    SomeKeyValueTypedPipe
     .mapWithValue(dict) { case ((key, value), (dictForKeys, dictForValues)) =>
       (dictForKeys.get.getOrElse(key, key), dictForValues.get.getOrElse(value, value)) }