Skip to content

Commit 7950b8a

Browse files
committed
add BireducibleLaws
1 parent 2bd1965 commit 7950b8a

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* Copyright (c) 2015 Typelevel
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy of
5+
* this software and associated documentation files (the "Software"), to deal in
6+
* the Software without restriction, including without limitation the rights to
7+
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8+
* the Software, and to permit persons to whom the Software is furnished to do so,
9+
* subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in all
12+
* copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16+
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18+
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20+
*/
21+
22+
package cats
23+
package laws
24+
25+
import cats.data.Ior
26+
import cats.kernel.laws.IsEq
27+
28+
trait BireducibleLaws[F[_, _]] extends BifoldableLaws[F] {
29+
implicit def F: Bireducible[F]
30+
31+
def bireduceLeftConsistentWithDefaultImplementation[A, B](
32+
fab: F[A, B],
33+
ma: (A, A) => A,
34+
mb: (B, B) => B
35+
): IsEq[A Ior B] = {
36+
val obtained = F.bireduceLeft(fab)(ma, mb)
37+
val expected = Bireducible.bireduceLeft(fab)(ma, mb)
38+
39+
obtained <-> expected
40+
}
41+
42+
def bireduceRightConsistentWithDefaultImplementation[A, B](
43+
fab: F[A, B],
44+
ma: (A, Eval[A]) => Eval[A],
45+
mb: (B, Eval[B]) => Eval[B]
46+
): IsEq[A Ior B] = {
47+
val obtained = F.bireduceRight(fab)(ma, mb)
48+
val expected = Bireducible.bireduceRight(fab)(ma, mb)
49+
50+
obtained.value <-> expected.value
51+
}
52+
53+
def bireduceMapConsistentWithDefaultImplementation[A, B, C](
54+
fab: F[A, B],
55+
ma: A => C,
56+
mb: B => C
57+
)(implicit
58+
C: Semigroup[C]
59+
): IsEq[C] = {
60+
val obtained = F.bireduceMap(fab)(ma, mb)
61+
val expected = Bireducible.bireduceMap(fab)(ma, mb)
62+
63+
obtained <-> expected
64+
}
65+
66+
def bireduceConsistentWithDefaultImplementation[A, B](
67+
fab: F[A, B]
68+
)(implicit A: Semigroup[A], B: Semigroup[B]): IsEq[A Ior B] = {
69+
70+
val obtained = F.bireduce(fab)
71+
val expected = Bireducible.bireduce(fab)
72+
73+
obtained <-> expected
74+
}
75+
}

0 commit comments

Comments
 (0)