parity.py
 1  # SPDX-FileCopyrightText: 2022-present deepset GmbH <info@deepset.ai>
 2  #
 3  # SPDX-License-Identifier: Apache-2.0
 4  
 5  from haystack.core.component import component
 6  
 7  
 8  @component
 9  class Parity:
10      """
11      Redirects the value, unchanged, along the 'even' connection if even, or along the 'odd' one if odd.
12      """
13  
14      @component.output_types(even=int, odd=int)
15      def run(self, value: int):
16          """
17          :param value: The value to check for parity
18          """
19          remainder = value % 2
20          if remainder:
21              return {"odd": value}
22          return {"even": value}