1
import SwiftCheck
2
import Bow
3
import BowGenerators
4

5
public class MonadErrorLaws<F: MonadError & EquatableK & ArbitraryK> where F.E: Arbitrary {
6 1
    public static func check()  {
7 1
        leftZero()
8 1
        ensureConsistency()
9
    }
10
    
11 1
    private static func leftZero() {
12 1
        property("Left zero") <~ forAll { (a: Int, g: ArrowOf<Int, Int>, error: F.E) in
13 1
            let f = g.getArrow >>> F.pure
14 1
            return F.flatMap(F.raiseError(error), f) == F.raiseError(error)
15
        }
16
    }
17
    
18 1
    private static func ensureConsistency() {
19 1
        property("Ensure consistency") <~ forAll { (fa: KindOf<F, Int>, p: ArrowOf<Int, Bool>, error: F.E) in
20 1
            return F.ensure(fa.value, constant(error), p.getArrow) == F.flatMap(fa.value, { a in p.getArrow(a) ? F.pure(a) : F.raiseError(error) })
21
        }
22
    }
23
}

Read our documentation on viewing source code .

Loading