1
import Foundation
2

3
/// SemigroupK is a `Semigroup` that operates on kinds with one type parameter.
4
public protocol SemigroupK {
5
    /// Combines two values of the same type in the context implementing this instance.
6
    ///
7
    /// Implementations of this method must obey the associative law:
8
    ///
9
    ///     combineK(fa, combineK(fb, fc)) == combineK(combineK(fa, fb), fc)
10
    ///
11
    /// - Parameters:
12
    ///   - x: Left value in the combination.
13
    ///   - y: Right value in the combination.
14
    /// - Returns: Combination of the two values.
15
    static func combineK<A>(_ x: Kind<Self, A>, _ y: Kind<Self, A>) -> Kind<Self, A>
16
}
17

18
// MARK: Syntax for SemigroupK
19

20
public extension Kind where F: SemigroupK {
21
    /// Combines this value with another value of the same type.
22
    ///
23
    /// This is a convenience method to call `SemigroupK.combineK` as an instance method of this type.
24
    ///
25
    /// - Parameters:
26
    ///   - y: Right value in the combination.
27
    /// - Returns: Combination of the two values.
28 1
    func combineK(_ y: Kind<F, A>) -> Kind<F, A> {
29 1
        return F.combineK(self, y)
30
    }
31
}

Read our documentation on viewing source code .

Loading