1
import SwiftCheck
2
import Bow
3
import BowGenerators
4

5
public class FunctorFilterLaws<F: FunctorFilter & EquatableK & ArbitraryK> {
6 1
    public static func check() {
7 1
        mapFilterComposition()
8 1
        mapFilterMapConsistency()
9
    }
10
    
11 1
    private static func mapFilterComposition() {
12 1
        property("MapFilter composition") <~ forAll { (fa: KindOf<F, Int>, f: ArrowOf<Int, Option<Int>>, g: ArrowOf<Int, Option<Int>>) in
13 1
            return F.mapFilter(F.mapFilter(fa.value, f.getArrow), g.getArrow) == F.mapFilter(fa.value, { x in f.getArrow(x).flatMap(g.getArrow) })
14
        }
15
    }
16
    
17 1
    private static func mapFilterMapConsistency() {
18 1
        property("Consistency between mapFilter and map") <~ forAll { (fa: KindOf<F, Int>, b: Int) in
19 1
            let f: (Int) -> Int = constant(b)
20 1
            return F.mapFilter(fa.value, { x in Option.some(f(x)) }) == F.map(fa.value, f)
21
        }
22
    }
23
}

Read our documentation on viewing source code .

Loading