@cran/lib.vue.ref
Version:
Vue Reactivity Extensions
21 lines (18 loc) • 508 B
text/typescript
import { computed } from "vue";
import { type ArrayReducer, wrapArrayReducer } from "./ArrayReducer";
import { type MaybeWrapped, unwrap } from "../utility";
/**
* @since 0.0.1
* @category Array
* @inheritdoc Array#reduce
*/
export function useReduce<T, R> (
values: MaybeWrapped<Array<MaybeWrapped<T>>>,
callbackfn: ArrayReducer<T, R>,
initialValue?: R
) {
return computed(function compute ( ) {
return unwrap(values)
.reduce<R>(wrapArrayReducer(callbackfn), initialValue!);
});
}