use core::iter::repeat;
use crate::digit::Digit;
pub fn slice_add<T: Copy + Default + Digit>(dst: &mut [T], lhs: &[T], rhs: &[T]) -> bool {
dst.iter_mut().zip(
lhs.iter().chain(repeat(&T::ZERO)).zip(
rhs.iter().chain(repeat(&T::ZERO))
)
).fold(false, |mut c, (o, (a, b))| {
(*o, c) = a.carry_add(*b, c);
c
})
}
pub fn slice_add_inplace<T: Copy + Default + Digit>(lhs: &mut [T], rhs: &[T]) -> bool {
lhs.iter_mut().zip(
rhs.iter().chain(repeat(&T::ZERO))
).fold(false, |mut c, (o, a)| {
(*o, c) = a.carry_add(*o, c);
c
})
}
pub fn slice_mul_dig<T: Copy + Default + Digit>(dst: &mut [T], lhs: &[T], rhs: T) -> T {
dst.iter_mut().zip(
lhs.iter().chain(repeat(&T::ZERO))
).fold(T::ZERO, |mut c, (o, d)| {
(*o, c) = d.carry_mul(rhs, c);
c
})
}