eygraber
12/25/2023, 6:41 AMprivate val HtmlElement.isBlockTag: Boolean get() = when(this) {
is HtmlElement.HtmlTag.Header -> true
is HtmlElement.HtmlTag.Paragraph -> isExplicit
is HtmlElement.HtmlTag.HtmlList -> true
is HtmlElement.HtmlTag.ListItem -> children.firstOrNull()?.isBlockTag == true
else -> false
}
I can't tell if this is a general false positive, or only because of my specific logic (since the current HtmlElement will never be present in its own children).Daniel Pitts
12/27/2023, 6:40 PMchildren.take(1).any { it.isBlockTag }twisterrob
12/28/2023, 3:31 PMeygraber
12/28/2023, 3:37 PMtwisterrob
12/28/2023, 7:34 PMDaniel Pitts
12/28/2023, 7:36 PMtake(1) returns either an emptyList or a singleton list. any{...} then does iterate over it that list. In practice, the difference in efficiency in negligible, but the readability is higher IMO.twisterrob
12/28/2023, 7:39 PMDaniel Pitts
12/28/2023, 7:40 PMDaniel Pitts
12/28/2023, 7:42 PMval Iterable<Element>.isFirstBlockTag get() method of its own, just to keep it separate.Daniel Pitts
12/28/2023, 7:43 PMiterator().run { hasNext() && next().isBlockTag }Daniel Pitts
12/28/2023, 7:44 PMeygraber
12/28/2023, 7:45 PMis there a possibility that the second one is a block, but the first is not
No, not in my domain
firstOrNull().isBlockTag == true
I think
Boolean? == true is pretty standard for Kotlin. Would be better to not use qBool but for one off cases like this in private implementation I think it's fineDaniel Pitts
12/28/2023, 7:46 PMDaniel Pitts
12/28/2023, 7:47 PMfirstOrNull()?.isBlockTag ?: false which I think is slightly clearer.Daniel Pitts
12/28/2023, 7:48 PMeygraber
12/28/2023, 7:49 PMDaniel Pitts
12/28/2023, 7:49 PMtwisterrob
12/28/2023, 8:24 PM