import kotlinx.coroutines.*
import java.time.Instant
import kotlin.math.roundToInt
+import java.util.function.Function as JFunction
class PreProcessorContext private constructor(
val variables: MutableMap<String, ParserTree>,
}
}),
FOR_EACH(PreProcessorLexerTag { env, param, subNodes ->
- val itemToContext: (ParserTree) -> Map<String, ParserTree> = if (param == null)
- ParserTree::asPreProcessorMap
- else ({ mapOf(param to it) })
+ val itemToContext: JFunction<ParserTree, Map<String, ParserTree>> = if (param == null)
+ JFunction(ParserTree::asPreProcessorMap)
+ else JFunction { mapOf(param to it) }
val subTags = subNodes.filterIsInstance<ParserTreeNode.Tag>()
val list = subTags.singleOrNull { it isTag "in" }?.subNodes
val body = subTags.singleOrNull { it isTag "do" }?.subNodes
if (list != null && body != null)
list.mapSuspend { item ->
- PreProcessorUtils.processWithContext(env, env.context + itemToContext(item), body)
+ PreProcessorUtils.processWithContext(env, env.context + itemToContext.apply(item), body)
}.flatten()
else formatErrorToParserTree("Expected child tag [in] to take list input and child tag [do] to take loop body")
}),
MAP(PreProcessorLexerTag { env, param, subNodes ->
- val itemToContext: (ParserTree) -> Map<String, ParserTree> = if (param == null)
- ParserTree::asPreProcessorMap
- else ({ mapOf(param to it) })
+ val itemToContext: JFunction<ParserTree, Map<String, ParserTree>> = if (param == null)
+ JFunction(ParserTree::asPreProcessorMap)
+ else JFunction { mapOf(param to it) }
val subTags = subNodes.filterIsInstance<ParserTreeNode.Tag>()
val list = subTags.singleOrNull { it isTag "in" }?.subNodes
val body = subTags.singleOrNull { it isTag "do" }?.subNodes
if (list != null && body != null)
list.mapSuspend { item ->
- ParserTreeNode.Tag("item", null, PreProcessorUtils.processWithContext(env, env.context + itemToContext(item), body))
+ ParserTreeNode.Tag("item", null, PreProcessorUtils.processWithContext(env, env.context + itemToContext.apply(item), body))
}
else formatErrorToParserTree("Expected child tag [in] to take list input and child tag [do] to take loop body")
}),
object April1stModeSerializer : KeyedEnumSerializer<April1stMode>(April1stMode.entries)
val ApplicationCall.april1stMode: April1stMode
- get() = when (request.cookies["APRIL_1ST_MODE"]) {
- "always" -> April1stMode.ALWAYS
- "never" -> April1stMode.NEVER
- else -> April1stMode.DEFAULT
- }
+ get() = request.cookies["APRIL_1ST_MODE"]?.let { modeCookie ->
+ April1stMode.entries.firstOrNull { mode -> mode.name.equals(modeCookie, ignoreCase = true) }
+ } ?: April1stMode.DEFAULT
class JoinToHtmlConsumer<E>(val iterator: Iterator<E>) {
inline fun <T : Tag> T.invokeReceiver(separator: T.() -> Unit, body: T.(E) -> Unit) {