Add a function `replace()`
This commit is contained in:
parent
b13531aecf
commit
6577717cbf
|
@ -48,6 +48,19 @@ def ident(x: A) -> A:
|
|||
"The identity function. Output is identical to input."
|
||||
return x
|
||||
|
||||
def replace(replace_with: A) -> Callable[..., A]:
|
||||
"""
|
||||
Get a function which always returns a constant value, regardless of input
|
||||
|
||||
The argument `replace_with` is the value the the returned function should always
|
||||
return. The returned function can be used as if having any arity, and will always
|
||||
return the same value originally passed to `replace`.
|
||||
"""
|
||||
def constant(*args: Any, **kwargs: Any) -> A:
|
||||
"Always return a constant value, typically the one passed to `replace`"
|
||||
return replace_with
|
||||
return constant
|
||||
|
||||
# Partial Appliaction shorthand
|
||||
p = partial
|
||||
"An alias for partial application"
|
||||
|
|
Loading…
Reference in New Issue