/// <summary> /// Folds the either into an S /// https://en.wikipedia.org/wiki/Fold_(higher-order_function) /// </summary> /// <typeparam name="S">State</typeparam> /// <typeparam name="L">Left</typeparam> /// <typeparam name="R">Right</typeparam> /// <param name="self">Either to fold</param> /// <param name="state">Initial state</param> /// <param name="Right">Right fold function</param> /// <param name="Left">Left fold function</param> /// <returns>Folded state</returns> public static S Fold <L, R, S>(this EitherUnsafe <L, R> self, S state, Func <S, R, S> Right, Func <S, L, S> Left) => self.IsBottom ? state : self.IsRight ? self.Fold(state, Right) : self.Fold(state, Left);