Package: effect
Module: Reducer
Reverses the argument order of a reducer’s combine method.
When to use
Use when you want the right-hand value to act as the accumulator, or need to reverse a non-commutative reducer such as string concatenation.
Details
Reducer where combine(self, that) calls the original
reducer as combine(that, self).initialValue is preserved from the original reducer.combineAll is re-derived from the flipped combine (using the
default left-to-right fold), not carried over from the original.Example (Reversing string concatenation)
import { Reducer, String } from "effect"
const Prepend = Reducer.flip(String.ReducerConcat)
console.log(Prepend.combine("a", "b"))
// Output: "ba"
console.log(Prepend.combineAll(["a", "b", "c"]))
// Output: "cba"
See
makeCombiner.flip – the same operation on a plain CombinerSignature
declare const flip: <A>(reducer: Reducer<A>) => Reducer<A>
Since v4.0.0