spdx_tools.spdx.jsonschema.optional_utils

 1# SPDX-FileCopyrightText: 2022 spdx contributors
 2#
 3# SPDX-License-Identifier: Apache-2.0
 4from beartype.typing import Callable, Optional, TypeVar
 5
 6T = TypeVar("T")
 7S = TypeVar("S")
 8
 9
10def apply_if_present(function: Callable[[T], S], optional_value: Optional[T]) -> Optional[S]:
11    """
12    Apply the passed function to the optional value if it is not None. Else returns None.
13    """
14    return function(optional_value) if optional_value is not None else None
def apply_if_present( function: collections.abc.Callable[[~T], ~S], optional_value: Optional[~T]) -> Optional[~S]:
11def apply_if_present(function: Callable[[T], S], optional_value: Optional[T]) -> Optional[S]:
12    """
13    Apply the passed function to the optional value if it is not None. Else returns None.
14    """
15    return function(optional_value) if optional_value is not None else None

Apply the passed function to the optional value if it is not None. Else returns None.