Source code for aspis.common.apply_to

from typing import Callable, TypeVar

from .curry import curry

T = TypeVar("T")
R = TypeVar("R")


[docs] @curry def apply_to(val: T, func: Callable[[T], R]) -> R: """ Takes a value and applies a function to it. This function is also known as `thrush` combinator. Args: val (T): The value to apply the function to. func (Callable[[T], R]): The function to apply to the value. Returns: R: The result of applying the function to the value. Example: >>> apply_to(5, lambda x: x * 2) 10 >>> apply_to([1, 2, 3], len) 3 """ return func(val)