Class RuntimeCollectionTransform

java.lang.Object
io.github.protasm.jvmud.compiler.runtime.RuntimeCollectionTransform

public final class RuntimeCollectionTransform extends Object
Runtime helpers for LPC collection callbacks.
  • Method Details

    • filter

      public static Object filter(Object source, RuntimeCallable callback, Object[] extras, RuntimeContext runtime)
      Applies LPC filter() semantics to arrays, strings, and mappings.

      Mappings are filtered as key/value pairs and return a mapping. Other iterable values keep the existing JVMud behavior: each item is passed as the first callback argument and matching items are returned as an array.

    • map

      public static Object map(Object source, RuntimeCallable callback, Object[] extras, RuntimeContext runtime)
      Applies LPC map() semantics to arrays, strings, and mappings.

      Mappings are traversed as key/value pairs and return a mapping with the original keys and transformed values. Other iterable values return an array of callback results.

    • sortArray

      public static Object sortArray(Object source, RuntimeCallable callback, Object[] extras, RuntimeContext runtime)
      Applies callable-form LPC sort_array() semantics.

      The callback receives the two candidate values as $1 and $2. Additional arguments are forwarded starting at $3. A truthy callback result swaps the two candidate values, matching the selection-sort behavior historically used by JVMud's compiler lowering for sort_array(values, (: ... :)).