Skip to content

Commit

Permalink
TyrianAppF - Remove for comprehensions
Browse files Browse the repository at this point in the history
- Unwind a two-line for-comprehension into a flatMap call
- Replace a for-comprehension on lists, with a filter, into a call
  to the List.collect method.
  • Loading branch information
diesalbla authored and davesmith00000 committed Jul 12, 2023
1 parent 586c5b9 commit 0838844
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions tyrian/js/src/main/scala/tyrian/TyrianAppF.scala
Original file line number Diff line number Diff line change
Expand Up @@ -153,21 +153,15 @@ object TyrianAppF:
} yield {
val tyrianAppElement = element.asInstanceOf[HTMLElement]
val tyrianAppName = tyrianAppElement.dataset.get("tyrianApp")
val appSupplierOption = for {
appName <- tyrianAppName
appSupplier <- appDirectory.get(appName)
} yield appSupplier
appSupplierOption match
tyrianAppName.flatMap(appDirectory.get) match
case Some(appSupplier) =>
appSupplier.launch(tyrianAppElement, appElementFlags(tyrianAppElement))
case _ =>
println(s"Could not find an app entry for ${tyrianAppName.getOrElse("")}")
}

private def appElementFlags(tyrianAppElement: HTMLElement): Map[String, String] =
val appFlags = for {
(dataAttr, attrValue) <- tyrianAppElement.dataset
if dataAttr.startsWith("tyrianFlag")
flagName = dataAttr.replaceFirst("^tyrianFlag", "")
} yield (flagName, attrValue)
appFlags.toMap
tyrianAppElement.dataset.collect {
case (dataAttr, attrValue) if dataAttr.startsWith("tyrianFlag") =>
dataAttr.replaceFirst("^tyrianFlag", "") -> attrValue
}.toMap

0 comments on commit 0838844

Please sign in to comment.