Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use whenA instead of pattern matching #252

Merged
merged 1 commit into from
Jul 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions modules/ingestor/src/main/scala/ingestor.forum.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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] =
(
Expand Down
Loading