KthContext

interface KthContext

Contexts are the main entrypoint of the Karith API. Their primary function is to parse strings into expressions, which can then be calculated to obtain a result.

A context defines a certain set of operators, functions and constants that can be used in expressions.

A context can be built using the KthContext method, or by copying an existing context like KthContext.

You can parse a string into an expression using the parseExpression or parseExpressionWith method. Then you can calculate the expression's result using the KthExpression.calculateResult method.

A default context KthContext is available. Functions from this class can be used directly without having to create a context: the default context will be used.

Inheritors

Types

Link copied to clipboard
interface Builder : KthBuilder

Builder interface for KthContext.

Link copied to clipboard

A default context that includes Modules.BASE, Modules.MATH and Operators.POWER.

Functions

Link copied to clipboard
@JvmName(name = "calculateResultExt")
open fun String.calculateResult(): KthParsingAndCalculationResult

Parses an arithmetic expression from the receiving string, then return its result.

Parses an arithmetic expression from the given string, then return its result.

Link copied to clipboard
@JvmName(name = "calculateResultWithExt")
open fun String.calculateResultWith(vararg inputVars: Pair<String, Number>): KthParsingAndCalculationResult

Parses an arithmetic expression from the receiving string, then return its result.

Parses an arithmetic expression from the given string, then return its result.

Link copied to clipboard
abstract fun clearCache()

Clears the expression cache of the context.

Link copied to clipboard
abstract fun copy(builder: KthContext.Builder.() -> Unit): KthContext

Copies this context to create a new context containing the same elements.

Link copied to clipboard
@JvmName(name = "parseExpressionExt")
open fun String.parseExpression(): KthParsingResult

Parses an arithmetic expression from the receiving string.

Parses an arithmetic expression from the given string.

Link copied to clipboard
@JvmName(name = "parseExpressionWithExt")
open fun String.parseExpressionWith(vararg declaredVars: String): KthParsingResult

Parses an arithmetic expression from the receiving string and given declared variables.

abstract fun parseExpressionWith(expr: String, vararg declaredVars: String): KthParsingResult

Parses an arithmetic expression from the given string and declared variables.