let mut ctx = Context { keychain };
let (mut tx, sum) = elems.iter().fold(
(Transaction::empty(), BlindSum::new()),
|acc, elem| elem(&mut ctx, acc),
);
i mean
(Transaction::empty(), BlindSum::new()) - initial object
|acc, elem| - accumulator and current
but how interpret
elem(&mut ctx, acc)
?
cuviper
February 22, 2018, 8:23am
2
It looks like elem
is a function or closure which you are calling with two parameters, and it must return the same accumulator type for the fold
.
there is no declared function with ‘elem’ name
|acc, elem| elem(&mut ctx, acc)
This is a closure taking two parameters acc and elem, returning what elem is returning. Makes sense?
jonh
February 22, 2018, 10:19am
5
let (mut tx, kern, sum) = elems.iter().fold(
(Transaction::empty(), TxKernel::empty(), BlindSum::new()),
|acc, elem| elem(&mut ctx, acc),
);
then what will result of fold? last item in elems?
jonh
February 22, 2018, 10:53am
7
Elems are the Closures being iterated over. The result of the fold will be the return value of the last call to last closure in the elems vec. Its input depends on prior accumulated values. (If elems is empty then it is just the initial value.)
thanks a lot
i have found how elems are prepared...
removal of the brain
1 Like