### AviatorScript Hello World Example Source: https://github.com/killme2008/aviatorscript/blob/master/README-EN.md A basic AviatorScript demonstrating printing a string, creating a tuple, calculating its sum using reduce, and accessing Java Date object properties like year and month. String interpolation using #{...} is also shown. ```aviatorscript p("Hello, AviatorScript!"); let a = tuple(1, 2, 3, 4, 5); p("sum of a is: " + reduce(a, +, 0)); let date = new java.util.Date(); p("The year is: "+ getYear(date)); p("The month is: #{getMonth(date)}"); ``` -------------------------------- ### Execute Regular Expression Matching Source: https://context7.com/killme2008/aviatorscript/llms.txt Shows how to perform pattern matching using the =~ operator. It includes examples of extracting data via capturing groups and performing boolean validation against strings. ```java import com.googlecode.aviator.AviatorEvaluator; import java.util.Map; public class RegularExpressionExample { public static void main(String[] args) { String email = "killme2008@gmail.com"; Map env = AviatorEvaluator.newEnv("email", email); String username = (String) AviatorEvaluator.execute("email=~/([\\w0-8]+)@\\w+[\\.\\w+]+/ ? $1 : 'unknown'", env); System.out.println(username); Boolean matches = (Boolean) AviatorEvaluator.execute("email=~/.*@gmail\\.com$/", env); System.out.println(matches); } } ``` -------------------------------- ### Manipulate Collections and Sequences Source: https://context7.com/killme2008/aviatorscript/llms.txt Illustrates working with arrays, lists, maps, and sets using the seq namespace. Includes examples of iteration, filtering, mapping, and reducing data. ```aviator let a = seq.array(int, 1, 2, 3, 4); let r = range(-5, 5); let s = seq.set(99, 100, 101); let m = seq.map("a", 1, "b", 2, "c", 3); let n = seq.list("car", "bus", "bike"); for e in m { println(e.key + "=" + e.value); } let doubled = map(a, lambda(x) -> x * 2 end); let sum = reduce(a, +, 0); let evens = filter(r, lambda(x) -> x % 2 == 0 end); let c = comparator(lambda(x, y) -> x > y end); println("sorted desc: " + sort(n, c)); ``` -------------------------------- ### Set Execution Timeout for AviatorScript Source: https://github.com/killme2008/aviatorscript/blob/master/README-EN.md Illustrates how to set an execution timeout for AviatorScript to prevent resource exhaustion by disruptive scripts. This example is based on the AviatorScript test suite. ```java import com.googlecode.aviator.AviatorEvaluator; import com.googlecode.aviator.Expression; import com.googlecode.aviator.ExecutionTimer; import java.util.Map; import java.util.concurrent.TimeUnit; public class TimeoutExample { public static void main(String[] args) { String script = "while(true){}"; // Infinite loop Expression compiled = AviatorEvaluator.compile(script); try { // Set a timeout of 1 second compiled.execute(null, 1, TimeUnit.SECONDS); } catch (Exception e) { System.out.println("Execution timed out: " + e.getMessage()); } } } ``` -------------------------------- ### Serialize Compiled AviatorScript Results Source: https://github.com/killme2008/aviatorscript/blob/master/README-EN.md Demonstrates how to serialize compiled AviatorScript results, which can be used for caching and accelerating compilation. This example is based on the AviatorScript test suite. ```java import com.googlecode.aviator.AviatorEvaluator; import com.googlecode.aviator.Expression; import java.util.Map; public class SerializeExample { public static void main(String[] args) throws Exception { String script = "let a = 1; let b = 2; a + b;"; Expression compiled = AviatorEvaluator.compile(script); // Serialize the compiled expression byte[] bytes = AviatorEvaluator.serialize(compiled); // Deserialize the compiled expression Expression deserialized = AviatorEvaluator.deserialize(bytes); // Execute the deserialized expression Object result = deserialized.execute(); System.out.println("Deserialized result: " + result); } } ``` -------------------------------- ### Download and Install AviatorScript Shell Script Source: https://github.com/killme2008/aviatorscript/blob/master/README-EN.md This snippet shows how to download the AviatorScript shell script using wget and make it executable using chmod. Ensure the script is placed in a directory included in your system's PATH environment variable. ```shell wget https://raw.githubusercontent.com/killme2008/aviator/master/bin/aviator chmod u+x aviator ``` -------------------------------- ### Override Operators with Custom Implementations Source: https://context7.com/killme2008/aviatorscript/llms.txt Illustrates how to extend AviatorScript by overriding built-in operators. The example creates a 'SafeDivide' function that prevents division-by-zero errors by returning zero instead of throwing an exception. ```java import com.googlecode.aviator.AviatorEvaluator; import com.googlecode.aviator.lexer.token.OperatorType; import com.googlecode.aviator.runtime.RuntimeUtils; import com.googlecode.aviator.runtime.function.AbstractFunction; import com.googlecode.aviator.runtime.function.FunctionUtils; import com.googlecode.aviator.runtime.type.*; import java.math.BigDecimal; import java.util.Map; public class OperatorOverloadExample { public static class SafeDivide extends AbstractFunction { @Override public String getName() { return "/"; } @Override public AviatorObject call(Map env, AviatorObject arg1, AviatorObject arg2) { if (FunctionUtils.getNumberValue(arg2, env).doubleValue() == 0) { return new AviatorDecimal(0); } BigDecimal left = AviatorNumber.valueOf(arg1.getValue(env)).toDecimal(env); BigDecimal right = AviatorNumber.valueOf(arg2.getValue(env)).toDecimal(env); return AviatorDecimal.valueOf(left.divide(right, RuntimeUtils.getMathContext(env))); } } public static void main(String[] args) { AviatorEvaluator.addOpFunction(OperatorType.DIV, new SafeDivide()); System.out.println(AviatorEvaluator.execute("4 - 1/0 + 3")); System.out.println(AviatorEvaluator.execute("4 - 1/2.0 + 3")); } } ``` -------------------------------- ### Organize Code with Modules Source: https://context7.com/killme2008/aviatorscript/llms.txt Shows how to define a module in one file and import/use it in another using the require function. ```aviator ## module.av let m = seq.map(); m.add = lambda(x, y) -> x + y end; m.sub = lambda(x, y) -> x - y end; __MODULE__.exports = m; ## use_module.av let math_ops = require('module.av'); println(math_ops.add(10, 5)); ``` -------------------------------- ### Execute AviatorScript File Source: https://github.com/killme2008/aviatorscript/blob/master/README-EN.md This command executes a saved AviatorScript file named 'hello.av'. The script's output will be displayed in the console. ```shell aviator hello.av ``` -------------------------------- ### Execute AviatorScript and Download JAR Source: https://github.com/killme2008/aviatorscript/blob/master/README-EN.md This command executes the downloaded AviatorScript. Upon first execution, it automatically downloads the latest aviator jar file to the ~/.aviatorscript directory. The output shows the download progress and usage information. ```shell aviator ``` -------------------------------- ### Import Java Methods as AviatorScript Functions Source: https://context7.com/killme2008/aviatorscript/llms.txt Demonstrates how to register Java instance and static methods into custom AviatorScript namespaces. This allows calling Java logic directly within script expressions. ```java import com.googlecode.aviator.AviatorEvaluator; public class JavaMethodFunctionsExample { public static void main(String[] args) throws Exception { AviatorEvaluator.addInstanceFunctions("s", String.class); AviatorEvaluator.execute("println(s.indexOf('hello', 'l'))"); AviatorEvaluator.execute("println(s.replaceAll('hello', 'l', 'x'))"); AviatorEvaluator.addStaticFunctions("math", Math.class); System.out.println(AviatorEvaluator.execute("math.abs(-3)")); System.out.println(AviatorEvaluator.execute("math.pow(2, 10)")); } } ``` -------------------------------- ### Execute AviatorScript Files in Java Source: https://context7.com/killme2008/aviatorscript/llms.txt Demonstrates how to load and execute an external .av script file within a Java application. It includes enabling Java method reflection for advanced interoperability. ```java import com.googlecode.aviator.AviatorEvaluator; import com.googlecode.aviator.Expression; import com.googlecode.aviator.runtime.JavaMethodReflectionFunctionMissing; public class RunScriptExample { public static void main(String[] args) throws Exception { AviatorEvaluator.getInstance() .setFunctionMissing(JavaMethodReflectionFunctionMissing.getInstance()); Expression exp = AviatorEvaluator.getInstance().compileScript("examples/hello.av"); exp.execute(); } } ``` -------------------------------- ### Handle Exceptions and Java Interop Source: https://context7.com/killme2008/aviatorscript/llms.txt Demonstrates try-catch blocks for error handling and accessing Java classes directly within AviatorScript. ```aviator try { throw new IllegalArgumentException("test error"); } catch(IllegalArgumentException e) { p("caught IllegalArgumentException"); pst(e); } catch(e) { p("caught generic exception"); pst(e); } use java.util.Date; let d = new Date(); p(type(d)); p("Year: #{getYear(d)}"); ``` -------------------------------- ### Define Functions and Closures in AviatorScript Source: https://context7.com/killme2008/aviatorscript/llms.txt Shows how to define reusable functions and create stateful closures using lambda expressions. Closures allow for maintaining internal state across multiple calls. ```aviator fn add(x, y) { return x + y; } three = add(1, 2); println(three); let counter = lambda() -> let c = 0; lambda() -> let result = c; c = c + 1; return result; end end; let c1 = counter(); let c2 = counter(); for i in range(0, 5) { println("c1: " + c1() + ", c2: " + c2()); } ``` -------------------------------- ### Perform High-Precision Arithmetic with BigInt and Decimal Source: https://context7.com/killme2008/aviatorscript/llms.txt Demonstrates the use of built-in BigInt and BigDecimal types for arbitrary precision calculations. It shows how to use the 'M' suffix for literals and how to integrate Java BigInteger/BigDecimal objects into the evaluation environment. ```java import com.googlecode.aviator.AviatorEvaluator; import com.googlecode.aviator.Options; import java.math.BigDecimal; import java.math.BigInteger; import java.math.MathContext; import java.util.Map; public class BigNumberExample { public static void main(String[] args) { Object rt = AviatorEvaluator.execute("9223372036854775807100.356M * 2"); System.out.println(rt + " " + rt.getClass()); rt = AviatorEvaluator.execute("92233720368547758074+1000"); System.out.println(rt + " " + rt.getClass()); BigInteger a = new BigInteger(String.valueOf(Long.MAX_VALUE) + String.valueOf(Long.MAX_VALUE)); BigDecimal b = new BigDecimal("3.2"); BigDecimal c = new BigDecimal("9999.99999"); Map env = AviatorEvaluator.newEnv("a", a, "b", b, "c", c); System.out.println(AviatorEvaluator.execute("a+10000000000000000000", env)); System.out.println(AviatorEvaluator.execute("b+c*2", env)); AviatorEvaluator.setOption(Options.MATH_CONTEXT, MathContext.DECIMAL64); System.out.println(AviatorEvaluator.execute("a*b/c", env)); } } ``` -------------------------------- ### Define AviatorScript Functions Using Lambda Expressions Source: https://context7.com/killme2008/aviatorscript/llms.txt Illustrates how to define functions within AviatorScript using lambda expressions, allowing for dynamic function creation without writing Java code. This includes defining curried functions and demonstrating closure behavior where variables are captured at the time of function definition. ```java import com.googlecode.aviator.AviatorEvaluator; import java.util.HashMap; import java.util.Map; public class LambdaExample { public static void main(String[] args) { // Define function using lambda expression AviatorEvaluator.defineFunction("test", "lambda(x) -> lambda(y) -> lambda(z) -> x + y + z end end end"); Map env = new HashMap<>(); env.put("x", 1); env.put("y", 2); env.put("z", 3); // Call curried function System.out.println(AviatorEvaluator.execute("test(4)(5)(6)", env)); // Output: 15 // Closure example - captures variable at definition time String exp = "a=1; b = lambda(x) -> a + x end; a=4; b(5)"; System.out.println(AviatorEvaluator.execute(exp)); // Output: 6 } } ``` -------------------------------- ### POST /evaluate Source: https://context7.com/killme2008/aviatorscript/llms.txt Executes a script expression string directly without compilation caching. ```APIDOC ## POST /evaluate ### Description Executes a simple expression string and returns the result immediately. ### Method POST ### Endpoint /evaluate ### Parameters #### Request Body - **expression** (string) - Required - The script expression to evaluate. - **env** (map) - Optional - A map of variable names and values. ### Request Example { "expression": "'hello,' + name", "env": {"name": "aviator"} } ### Response #### Success Response (200) - **result** (any) - The evaluated result of the expression. #### Response Example { "result": "hello,aviator" } ``` -------------------------------- ### Compile and Execute AviatorScript Expressions Source: https://context7.com/killme2008/aviatorscript/llms.txt Shows how to compile an AviatorScript expression once and then execute it multiple times with different variable environments. This approach improves performance for repeated evaluations by avoiding recompilation. It also demonstrates how to retrieve the variable names used within a compiled expression. ```java import com.googlecode.aviator.AviatorEvaluator; import com.googlecode.aviator.Expression; import java.util.HashMap; import java.util.Map; public class CompileExample { public static void main(String[] args) { // Compile expression String expression = "a-(b-c)>100"; Expression compiledExp = AviatorEvaluator.compile(expression); // Create environment with variables Map env = new HashMap<>(); env.put("a", 100.3); env.put("b", 45); env.put("c", -199.100); // Execute compiled expression Boolean result = (Boolean) compiledExp.execute(env); System.out.println(result); // Output: false // Get variable names from expression System.out.println("Variables: " + compiledExp.getVariableFullNames()); } } ``` -------------------------------- ### POST /compile Source: https://context7.com/killme2008/aviatorscript/llms.txt Compiles an expression once for reuse, allowing for multiple executions with different environments. ```APIDOC ## POST /compile ### Description Compiles an expression string into an Expression object for high-performance repeated execution. ### Method POST ### Endpoint /compile ### Parameters #### Request Body - **expression** (string) - Required - The script expression to compile. ### Request Example { "expression": "a-(b-c)>100" } ### Response #### Success Response (200) - **expressionId** (string) - Unique identifier for the compiled expression. - **variables** (array) - List of variable names found in the expression. #### Response Example { "expressionId": "exp_12345", "variables": ["a", "b", "c"] } ``` -------------------------------- ### Utilize Built-in String Functions Source: https://context7.com/killme2008/aviatorscript/llms.txt Shows how to perform common string operations like searching, splitting, and manipulation using the 'string' namespace prefix in AviatorScript. ```java import com.googlecode.aviator.AviatorEvaluator; import java.util.Arrays; public class StringFunctionsExample { public static void main(String[] args) { System.out.println(AviatorEvaluator.execute("string.length('hello')")); System.out.println(AviatorEvaluator.execute("string.contains('hello','h')")); System.out.println(AviatorEvaluator.execute("string.substring('hello',1,3)")); String[] parts = (String[]) AviatorEvaluator.execute("string.split('hello world,aviator',' ')"); System.out.println(Arrays.toString(parts)); } } ``` -------------------------------- ### Execute AviatorScript Expressions Directly Source: https://context7.com/killme2008/aviatorscript/llms.txt Demonstrates how to execute AviatorScript expressions directly as strings, retrieving the result immediately. This method is suitable for simple, one-off evaluations without performance concerns related to compilation caching. It supports basic arithmetic, string concatenation, and boolean logic with variable substitution using `newEnv`. ```java import com.googlecode.aviator.AviatorEvaluator; public class DirectExecutionExample { public static void main(String[] args) { // Execute simple arithmetic expression Long result = (Long) AviatorEvaluator.execute("1+2+3"); System.out.println(result); // Output: 6 // Execute with variables using newEnv helper String hello = (String) AviatorEvaluator.execute( "'hello,' + name", AviatorEvaluator.newEnv("name", "aviator") ); System.out.println(hello); // Output: hello,aviator // Execute boolean expression Boolean check = (Boolean) AviatorEvaluator.execute("3 > 2 && 5 < 10"); System.out.println(check); // Output: true } } ``` -------------------------------- ### Register and Use Custom AviatorScript Functions in Java Source: https://context7.com/killme2008/aviatorscript/llms.txt Explains how to extend AviatorScript's functionality by registering custom Java functions. This involves creating a class that extends `AbstractFunction` and implementing the `call` method. These custom functions can then be used directly within AviatorScript expressions. ```java import com.googlecode.aviator.AviatorEvaluator; import com.googlecode.aviator.runtime.function.AbstractFunction; import com.googlecode.aviator.runtime.function.FunctionUtils; import com.googlecode.aviator.runtime.type.AviatorObject; import java.util.Map; class AddFunction extends AbstractFunction { @Override public AviatorObject call(Map env, AviatorObject arg1, AviatorObject arg2) { Number left = FunctionUtils.getNumberValue(arg1, env); Number right = FunctionUtils.getNumberValue(arg2, env); return FunctionUtils.wrapReturn(left.doubleValue() + right.doubleValue()); } @Override public String getName() { return "add"; } } public class AddFunctionExample { public static void main(String[] args) { // Register custom function AviatorEvaluator.addFunction(new AddFunction()); // Use custom function in expressions System.out.println(AviatorEvaluator.execute("add(1,2)")); // Output: 3.0 System.out.println(AviatorEvaluator.execute("add(add(1,2),100)")); // Output: 103.0 } } ``` -------------------------------- ### Add AviatorScript Dependency (Maven) Source: https://github.com/killme2008/aviatorscript/blob/master/README-EN.md This snippet shows how to add the AviatorScript library as a dependency in a Maven project. Replace '{version}' with the desired version of AviatorScript. ```xml com.googlecode.aviator aviator {version} ``` -------------------------------- ### Execute Sequence and Collection Operations Source: https://context7.com/killme2008/aviatorscript/llms.txt Covers functional programming patterns such as map, reduce, and filter applied to Java collections using the AviatorScript sequence abstraction. ```java import com.googlecode.aviator.AviatorEvaluator; import java.util.*; public class SeqExample { public static void main(String[] args) { int[] a = new int[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; Map env = AviatorEvaluator.newEnv("a", a); System.out.println(AviatorEvaluator.execute("count(a)", env)); System.out.println(AviatorEvaluator.execute("reduce(a,+,0)", env)); ArrayList list = new ArrayList<>(Arrays.asList(3, 100, -100)); env.put("list", list); System.out.println(AviatorEvaluator.execute("sort(list)", env)); } } ``` -------------------------------- ### Configuring Aviator Evaluator Instance with Features Source: https://context7.com/killme2008/aviatorscript/llms.txt Explains how to create isolated AviatorEvaluator instances with specific feature sets for sandboxing. This allows fine-grained control over available language features, enhancing security and predictability. ```java import com.googlecode.aviator.AviatorEvaluator; import com.googlecode.aviator.AviatorEvaluatorInstance; import com.googlecode.aviator.Feature; import com.googlecode.aviator.Options; public class ConfigureInstanceExample { public static void main(String[] args) { // Create new isolated instance AviatorEvaluatorInstance instance = AviatorEvaluator.newInstance(); // Configure options instance.setOption(Options.USE_USER_ENV_AS_TOP_ENV_DIRECTLY, false); // Enable only specific features for sandboxing instance.setOption(Options.FEATURE_SET, Feature.asSet( Feature.Assignment, Feature.ForLoop, Feature.WhileLoop, Feature.Lambda, Feature.Let )); // Execute with limited features System.out.println(instance.execute( "let square = lambda(x) -> x*2 end; for x in range(0, 10) { p(square(x)); }" )); } } ``` -------------------------------- ### POST /functions Source: https://context7.com/killme2008/aviatorscript/llms.txt Registers a custom Java function or a lambda expression to extend the script capabilities. ```APIDOC ## POST /functions ### Description Registers a new function that can be called within AviatorScript expressions. ### Method POST ### Endpoint /functions ### Parameters #### Request Body - **name** (string) - Required - The name of the function. - **definition** (string) - Required - The lambda expression or reference to Java implementation. ### Request Example { "name": "add", "definition": "lambda(x, y) -> x + y end" } ### Response #### Success Response (200) - **status** (string) - Confirmation of registration. #### Response Example { "status": "success" } ``` -------------------------------- ### Perform Mathematical Operations Source: https://context7.com/killme2008/aviatorscript/llms.txt Explains the usage of the 'math' namespace for basic, logarithmic, and trigonometric calculations within AviatorScript. ```java import com.googlecode.aviator.AviatorEvaluator; public class MathFunctionsExample { public static void main(String[] args) { System.out.println(AviatorEvaluator.execute("math.abs(-3)")); System.out.println(AviatorEvaluator.execute("math.pow(-3,2)")); System.out.println(AviatorEvaluator.execute("math.sqrt(16.0)")); System.out.println(AviatorEvaluator.execute("math.sin(0)")); } } ``` -------------------------------- ### Configuring Execution Timeout in AviatorScript Source: https://context7.com/killme2008/aviatorscript/llms.txt Demonstrates how to set an execution timeout for AviatorScript expressions to prevent resource exhaustion from infinite loops or long-running computations. It catches the TimeoutException. ```java import com.googlecode.aviator.AviatorEvaluator; import com.googlecode.aviator.Options; import com.googlecode.aviator.exception.TimeoutException; public class TimeoutExample { public static void main(String[] args) { // Set 100ms timeout AviatorEvaluator.setOption(Options.EVAL_TIMEOUT_MS, 100); try { // This infinite loop will timeout AviatorEvaluator.execute("while(true) { }"); } catch (TimeoutException e) { System.out.println("Execution timed out as expected"); } } } ``` -------------------------------- ### Accessing Java Object Properties with AviatorScript Source: https://context7.com/killme2008/aviatorscript/llms.txt Demonstrates how to access nested Java object properties using AviatorScript's dot notation syntax sugar. It shows how to read and modify properties of Java objects within the Aviator environment. ```java import com.googlecode.aviator.AviatorEvaluator; import java.util.*; public class VariableExample { public static class Bar { private String name = "bar"; public String getName() { return name; } public void setName(String name) { this.name = name; } } public static class Foo { public int i; public float f; public Date date; public Bar[] bars = new Bar[1]; public Map context = new HashMap<>(); public Foo(int i, float f, Date date) { this.i = i; this.f = f; this.date = date; this.bars[0] = new Bar(); } // getters and setters... } public static void main(String[] args) { Foo foo = new Foo(100, 3.14f, new Date()); foo.context.put("key", "value"); Map env = AviatorEvaluator.newEnv("foo", foo); // Access nested properties System.out.println(AviatorEvaluator.execute("foo.i", env)); // 100 System.out.println(AviatorEvaluator.execute("foo.f", env)); // 3.14 System.out.println(AviatorEvaluator.execute("foo.bars[0].name", env)); // bar // Modify properties AviatorEvaluator.execute("#foo.bars[0].name = 'hello aviator'", env); System.out.println(foo.bars[0].getName()); // hello aviator } } ``` -------------------------------- ### Expression Serialization and Deserialization with AviatorScript Source: https://context7.com/killme2008/aviatorscript/llms.txt Shows how to serialize compiled AviatorScript expressions into byte arrays and deserialize them back. This is useful for caching compiled expressions or distributing them across different systems. ```java import com.googlecode.aviator.AviatorEvaluator; import com.googlecode.aviator.AviatorEvaluatorInstance; import com.googlecode.aviator.Expression; import com.googlecode.aviator.Options; import java.io.*; public class SerializeExample { public static void main(String[] args) throws Exception { // Enable serialization feature AviatorEvaluatorInstance engine = AviatorEvaluator.getInstance(); engine.setOption(Options.SERIALIZABLE, true); // Compile expression Expression exp = engine.compile("if (a>b) { return a; } else { return b; }"); System.out.println("Result: " + exp.execute(exp.newEnv("a", 42, "b", 99))); // Serialize to bytes byte[] bytes; try (ByteArrayOutputStream out = new ByteArrayOutputStream()) { ObjectOutputStream output = engine.newObjectOutputStream(out); output.writeObject(exp); output.close(); bytes = out.toByteArray(); } System.out.println("Serialized bytes length: " + bytes.length); // Deserialize and execute try (ByteArrayInputStream in = new ByteArrayInputStream(bytes)) { ObjectInputStream input = engine.newObjectInputStream(in); Expression newExp = (Expression) input.readObject(); System.out.println("Deserialized result: " + newExp.execute(newExp.newEnv("a", 42, "b", 99))); } } } ``` -------------------------------- ### AviatorScript Reduce Function for Aggregation Source: https://github.com/killme2008/aviatorscript/wiki/Home-(English)-(Draft-草稿-Incomplete-不完整) The 'reduce' function aggregates elements of a sequence using a provided function and an initial value. It takes a sequence, a function (which accepts an element and an accumulator), and an initial value, returning the final accumulated value. ```AviatorScript reduce(seq, fun, init) ``` -------------------------------- ### AviatorScript Sequence Exists (Not Nil) Predicate Source: https://github.com/killme2008/aviatorscript/wiki/Home-(English)-(Draft-草稿-Incomplete-不完整) The 'seq.exists()' method generates a predicate that evaluates to true if a sequence element is NOT nil. This is useful for filtering out nil values and processing only the existing elements in a sequence. ```AviatorScript seq.exists() ``` -------------------------------- ### AviatorScript Sequence Nil Check Predicate Source: https://github.com/killme2008/aviatorscript/wiki/Home-(English)-(Draft-草稿-Incomplete-不完整) The 'seq.nil()' method returns a predicate that checks if a sequence element is nil (null or undefined). This predicate is used in filtering to identify and select nil values within a sequence. ```AviatorScript seq.nil() ``` -------------------------------- ### AviatorScript Sequence Less Than or Equal To Predicate Source: https://github.com/killme2008/aviatorscript/wiki/Home-(English)-(Draft-草稿-Incomplete-不完整) The 'seq.le(value)' method returns a predicate that determines if a sequence element is less than or equal to the specified 'value'. This is useful for filtering sequences to include elements within a certain range. ```AviatorScript seq.le(value) ``` -------------------------------- ### Collection Predicate Functions Source: https://github.com/killme2008/aviatorscript/wiki/Home-(English)-(Draft-草稿-Incomplete-不完整) A set of predicate functions used for filtering and evaluating collection elements. ```APIDOC ## Collection Predicates (seq.*) ### Description These functions return predicates used primarily in filter operations. ### Available Predicates - **seq.eq(value)**: Returns true if element equals value. - **seq.neq(value)**: Returns true if element does not equal value. - **seq.gt(value)**: Returns true if element is greater than value. - **seq.ge(value)**: Returns true if element is greater than or equal to value. - **seq.lt(value)**: Returns true if element is less than value. - **seq.le(value)**: Returns true if element is less than or equal to value. - **seq.nil()**: Returns true if element is nil. - **seq.exists()**: Returns true if element is not nil. ### Usage Example filter(seq, seq.eq(3)) // Returns elements equal to 3 ``` -------------------------------- ### Collection Reduction Function Source: https://github.com/killme2008/aviatorscript/wiki/Home-(English)-(Draft-草稿-Incomplete-不完整) The reduce function aggregates collection elements into a single value using a provided function and initial state. ```APIDOC ## reduce(seq, fun, init) ### Description Applies a function to each element of a collection and an accumulator to reduce the collection to a single value. ### Method FUNCTION ### Parameters - **seq** (Collection) - Required - The collection to iterate over. - **fun** (Function) - Required - A function accepting two arguments: (element, accumulator). - **init** (Any) - Required - The initial value for the accumulator. ### Response - **result** (Any) - The final accumulated value. ``` -------------------------------- ### AviatorScript Sequence Inequality Predicate Source: https://github.com/killme2008/aviatorscript/wiki/Home-(English)-(Draft-草稿-Incomplete-不完整) The 'seq.neq(value)' method generates a predicate that evaluates to true if a sequence element is NOT equal to the provided 'value'. This is useful for excluding specific elements during filtering operations. ```AviatorScript seq.neq(value) ``` -------------------------------- ### AviatorScript Sequence Equality Predicate Source: https://github.com/killme2008/aviatorscript/wiki/Home-(English)-(Draft-草稿-Incomplete-不完整) The 'seq.eq(value)' method returns a predicate function that checks if a sequence element is equal to the specified 'value'. This is commonly used with filter functions to select elements that match a certain criterion. ```AviatorScript seq.eq(value) ``` -------------------------------- ### AviatorScript Sequence Less Than Predicate Source: https://github.com/killme2008/aviatorscript/wiki/Home-(English)-(Draft-草稿-Incomplete-不完整) The 'seq.lt(value)' method generates a predicate that evaluates to true if a sequence element is strictly less than the provided 'value'. It's employed in filtering operations to select elements below a specific value. ```AviatorScript seq.lt(value) ``` -------------------------------- ### AviatorScript Sequence Greater Than or Equal To Predicate Source: https://github.com/killme2008/aviatorscript/wiki/Home-(English)-(Draft-草稿-Incomplete-不完整) The 'seq.ge(value)' method returns a predicate that checks if a sequence element is greater than or equal to the specified 'value'. This predicate is used in filtering to include elements that meet or exceed a certain threshold. ```AviatorScript seq.ge(value) ``` -------------------------------- ### AviatorScript Sequence Greater Than Predicate Source: https://github.com/killme2008/aviatorscript/wiki/Home-(English)-(Draft-草稿-Incomplete-不完整) The 'seq.gt(value)' method creates a predicate that returns true if a sequence element is strictly greater than the specified 'value'. It's used for filtering sequences based on a 'greater than' condition. ```AviatorScript seq.gt(value) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.