Sequence

extension Sequence
extension Sequence where Element: Additive
extension Sequence where Element: Multiplicative
extension Sequence where Element: Monoid
extension Sequence where Element: MonoidView
  • let numbers = [1,2,3]
    let accumulatedAdditionFrom10 = numbers.accumulating(10,+) // => [10,11,13]
    

    Declaration

    Swift

    public func accumulating(
        _ initial: Element,
        _ op: (Element,Element) -> Element
    ) -> [Element]

    Return Value

    An array of values starting with the given initial, followed by each element combined with the accumulation with the given op.

Available where Element: Additive

  • let numbers = [2,1,2]
    let accumulated = numbers.accumulatingSum // => [0,2,3]
    

    Declaration

    Swift

    public var accumulatingSum: [Element] { get }

    Return Value

    An array of values from .zero, applying + to each element contained herein and the accumulative value.

Available where Element: Multiplicative

  • let numbers = [2,1,2]
    let accumulated = numbers.accumulatingProduct // => [1,2,2]
    

    Declaration

    Swift

    public var accumulatingProduct: [Element] { get }

    Return Value

    An array of values from .one, applying * to each element contained herein and the accumulative value.

Available where Element: Monoid

  • Declaration

    Swift

    public var reduced: Element { get }

    Return Value

    The values contained herein, reduced from the .identity value of the Monoid, composing with the <> operation of the Monoid.

Available where Element: MonoidView

  • Declaration

    Swift

    public var reduced: Element.Value { get }

    Return Value

    The values contained herein, reduced from the .identity value of the Monoid, composing with the <> operation of the Monoid.

Available where Element: Multiplicative

  • Declaration

    Swift

    public var product: Element { get }

    Return Value

    Product of all values contained herein.

Available where Element: Additive

  • sum

    Declaration

    Swift

    public var sum: Element { get }

    Return Value

    Sum of all values contained herein.