Package jjparse.data

Record Class Product<A,B>

java.lang.Object
java.lang.Record
jjparse.data.Product<A,B>
Type Parameters:
A - The type of the first value.
B - The type of the second value.
Record Components:
first - The first or left value of this Product.
second - The second or right value of this Product.

public record Product<A,B>(A first, B second) extends Record
A simple representation of a Product (or pair) as a record. This class is primarily used by the combinator Parsing.Parser.and(jjparse.Parsing.Parser<U>) to return two values without losing the type information and to offer convenient operations for the mapping and reduction of these two values.
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Product(A first, B second)
    Creates an instance of a Product record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    final boolean
    Indicates whether some other object is "equal to" this one.
    Returns the value of the first record component.
    <C> C
    fold(BiFunction<A,B,C> function)
    Reduces this Product to a value by applying the provided function to this Product's values.
    final int
    Returns a hash code value for this object.
    <C, D> Product<C,D>
    map(Function<A,C> first, Function<B,D> second)
    Maps this Product to a new one by mapping its values using the provided functions.
    static <A, B> Product<A,B>
    of(A first, B second)
    A shorthand for constructing a new Product.
    Returns the value of the second record component.
    final String
    Returns a string representation of this record class.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Product

      public Product(A first, B second)
      Creates an instance of a Product record class.
      Parameters:
      first - the value for the first record component
      second - the value for the second record component
  • Method Details

    • map

      public <C, D> Product<C,D> map(Function<A,C> first, Function<B,D> second)
      Maps this Product to a new one by mapping its values using the provided functions.
      Type Parameters:
      C - The target type of the first value.
      D - The target type of the second value.
      Parameters:
      first - The function that is used to map the first value of this Product.
      second - The function that is used to map the second value of this Product.
      Returns:
      A new Product whose values correspond to the mapped values of this Product.
    • fold

      public <C> C fold(BiFunction<A,B,C> function)
      Reduces this Product to a value by applying the provided function to this Product's values.
      Type Parameters:
      C - The type of the resulting value.
      Parameters:
      function - The function that is used to fold the first and second value to a new value.
      Returns:
      The result of applying the provided function to this Product's values.
    • of

      public static <A, B> Product<A,B> of(A first, B second)
      A shorthand for constructing a new Product.
      Type Parameters:
      A - The type of the first value.
      B - The type of the second value.
      Parameters:
      first - The first or left value of this Product.
      second - The second or right value of this Product.
      Returns:
      A new Product which consists of the provided values.
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • first

      public A first()
      Returns the value of the first record component.
      Returns:
      the value of the first record component
    • second

      public B second()
      Returns the value of the second record component.
      Returns:
      the value of the second record component