Class Cond<T extends ACell>

Type Parameters:
T - Result type of Op
All Implemented Interfaces:
IValidated, IWriteable

public class Cond<T extends ACell> extends AMultiOp<T>
Op representing a conditional expression. Child ops: 1. Should be condition / result pairs (with an optional single default result). 2. Are executed in sequence until the first condition succeeds 3. Are only executed if required, i.e. cond operates as a "short-circuiting" conditional.
  • Constructor Details

  • Method Details

    • create

      public static <T extends ACell> Cond<T> create(AOp<?>... ops)
      Create a Cond operation with the given nested operations
      Type Parameters:
      T - Return type of Cond
      Parameters:
      ops - Ops to execute conditionally
      Returns:
      Cond instance
    • recreate

      protected Cond<T> recreate(ASequence<AOp<ACell>> newOps)
      Description copied from class: AMultiOp
      Recreates this object with an updated list of child Ops.
      Specified by:
      recreate in class AMultiOp<T extends ACell>
      Returns:
    • create

      public static <T extends ACell> Cond<T> create(ASequence<AOp<ACell>> ops)
    • execute

      public <I extends ACell> Context<T> execute(Context<I> context)
      Description copied from class: AOp
      Executes this op with the given context. Must preserve depth unless an exceptional is returned.
      Specified by:
      execute in class AOp<T extends ACell>
      Type Parameters:
      I - Type of Context
      Parameters:
      context - Initial Context
      Returns:
      The updated Context after executing this operation
    • print

      public void print(StringBuilder sb)
      Description copied from class: AObject
      Prints this Object to a readable String Representation
      Specified by:
      print in class AObject
      Parameters:
      sb - StringBuilder to append to
    • opCode

      public byte opCode()
      Description copied from class: AOp
      Returns the opcode for this op
      Specified by:
      opCode in class AOp<T extends ACell>
      Returns:
      Opcode as a byte
    • read

      public static <T extends ACell> Cond<T> read(ByteBuffer b) throws BadFormatException
      Throws:
      BadFormatException
    • updateRefs

      public Cond<T> updateRefs(IRefFunction func)
      Description copied from class: ACell
      Updates all Refs in this object using the given function. The function *must not* change the hash value of Refs, in order to ensure structural integrity of modified data structures. This is a building block for a very sneaky trick that enables use to do a lot of efficient operations on large trees of smart references. Must return the same object if no Refs are altered.
      Overrides:
      updateRefs in class AMultiOp<T extends ACell>
      Parameters:
      func - Ref update function
      Returns:
      Cell with updated Refs