From 1b42617be06d103d9001a5447a91f3cbaa6b1797 Mon Sep 17 00:00:00 2001 From: Thanh Le Date: Tue, 2 Jul 2024 10:48:16 +0700 Subject: [PATCH] Use whenA instead of pattern matching --- .../src/main/scala/ingestor.forum.scala | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/modules/ingestor/src/main/scala/ingestor.forum.scala b/modules/ingestor/src/main/scala/ingestor.forum.scala index 2c809f2..2fa2b00 100644 --- a/modules/ingestor/src/main/scala/ingestor.forum.scala +++ b/modules/ingestor/src/main/scala/ingestor.forum.scala @@ -138,15 +138,14 @@ object ForumIngestor: (doc.id, doc.topicId) .flatMapN: (id, topicId) => doc.toSource(topicMap.get(topicId), topicId).map(id -> _) - .match - case Some(value) => value.some.pure[IO] - case _ => - val reason = doc.id.fold("missing doc._id; ")(_ => "") - + doc.topicId.fold("missing doc.topicId; ")(_ => "") - + doc.topicId - .map(id => topicMap.get(id).fold("topic or topic.name is missing")(_ => "")) - .getOrElse("") - info"failed to convert document to source: $doc because $reason".as(none) + .pure[IO] + .flatTap: source => + def reason = doc.id.fold("missing doc._id; ")(_ => "") + + doc.topicId.fold("missing doc.topicId; ")(_ => "") + + doc.topicId + .map(id => topicMap.get(id).fold("topic or topic.name is missing")(_ => "")) + .getOrElse("") + info"failed to convert document to source: $doc because $reason".whenA(source.isEmpty) private def toSource(topicName: Option[String], topicId: String): Option[ForumSource] = (