> S.reduce(S.flip(S.K),[],S.Left([1,2]))
[]
> S.reduce(S.flip(S.K),[],S.Right([1,2]))
[ 1, 2 ]
I was trying to understand sanctuary and its working can anybody explain the above outcomes in detail In my understanding S.reduce takes a mapping function and uses the input array which should be of type either and reduces it But why its empty array in first case and same array in second case
                        
Let's start with a more familiar example: using
S.reduceon an array.Now, let's specialize the type of
S.reduceto explain the behaviour above.Next, let's specialize the type of
S.reduceto see how it will operate on Either values.What can we do when given
S.Left ('foo')as theEither x a? We have anx('foo') but noa. Because we don't have anawe cannot make use of theb -> a -> bfunction. Thus, the onlybwe can possibly return is the initial value.What can we do when given
S.Right ('bar')as theEither x a? We have ana, which we could feed to theb -> a -> bfunction along with the initial value to produce another value of typeb.If
S.reducewere to return'initial:'or'initial:bar:bar:bar'in the case above it would still be conforming to the type signature, but thefantasy-land/reduceimplementation for Sanctuary's Either type applies the function exactly once when given a Right.