def resolveTargetContacts()

in common/src/main/scala/com/gu/anghammarad/common/Contacts.scala [23:30]


  def resolveTargetContacts(targets: List[Target], mappings: List[Mapping]): Try[List[Contact]] = for {
    exactMatches <- findExactMatches(targets, mappings)
    underSpecifiedMatches = findUnderSpecifiedMatches(targets, mappings)
    overSpecifiedMatches = findOverSpecifiedMatches(targets, mappings)
    contacts <- exactMatches.orElse(underSpecifiedMatches).orElse(overSpecifiedMatches).fold[Try[List[Contact]]] {
      Fail(s"Could not find matching contacts for $targets")
    }(Success(_))
  } yield contacts