anymerge
anymerge
¶
Reducer
¶
Reducer(reducer: ReducerCallable) -> ReducerInfo
Reducer(*, deep: Literal[True]) -> ReducerInfo
Reducer(reducer: EllipsisType) -> ReducerInfo
Reducer(
reducer: ReducerCallable | EllipsisType | None = None,
*,
deep: bool | None = None,
) -> ReducerInfo
Create a ReducerInfo
object with the given reducer
callable or deep
set to True.
PARAMETER | DESCRIPTION |
---|---|
reducer
|
The reducer callable to apply to the field. If set to
TYPE:
|
deep
|
Whether to apply the reducer deeply.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
ReducerInfo
|
A |
Examples:
Define a reducer callable:
>>> Reducer(operator.add)
To apply a reducer deeply, either use ...
as the reducer
argument or set deep
to True
:
>>> Reducer(...)
>>> Reducer(deep=True)
Source code in src/anymerge/_api.py
merge
¶
merge(
a: T,
b: Any,
*,
default_reducer: ReducerInfo = DEFAULT_REDUCER,
) -> T
Merge two instances of data models.
PARAMETER | DESCRIPTION |
---|---|
a
|
The first instance to merge. This should contain all the annotations with the reducer information.
TYPE:
|
b
|
The second instance to merge.
TYPE:
|
default_reducer
|
The default reducer to apply to fields.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
T
|
The merged instance. |
Source code in src/anymerge/_merger.py
reduce
¶
reduce(
initial: T,
iterable: Iterable[Any],
*,
default_reducer: ReducerInfo = DEFAULT_REDUCER,
) -> T
Reduce an iterable of instances of data models.
PARAMETER | DESCRIPTION |
---|---|
initial
|
The initial instance to reduce. This should contain all the annotations with the reducer information.
TYPE:
|
iterable
|
The iterable of instances to reduce.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
T
|
The reduced instance. |