@@ -7,32 +7,33 @@ import scala.language.higherKinds
7
7
8
8
object EitherUtil {
9
9
10
- def sequence [L , R , M [X ] <: TraversableOnce [X ]](seq : M [Either [L , R ]])
11
- (implicit cbf : CanBuildFrom [Nothing , R , M [R ]]): Either [L , M [R ]] = {
10
+ def sequence [L , R , M [X ] <: TraversableOnce [X ]](
11
+ seq : M [Either [L , R ]]
12
+ )(implicit cbf : CanBuildFrom [Nothing , R , M [R ]]): Either [L , M [R ]] =
12
13
Right {
13
- seq.foldRight(List .empty[R ]) { case (a, res) =>
14
- a match {
15
- case Left (l) => return Left [L , M [R ]](l)
16
- case Right (r) => r :: res
14
+ seq
15
+ .foldRight(List .empty[R ]) {
16
+ case (a, res) =>
17
+ a match {
18
+ case Left (l) => return Left [L , M [R ]](l)
19
+ case Right (r) => r :: res
20
+ }
17
21
}
18
- }
19
22
.to[M ]
20
23
}
21
- }
22
24
23
- def map [L , K , R ](seq : Map [K , Either [L , R ]], leftCombine : (K , L ) => L ): Either [L , Map [K , R ]] = {
25
+ def map [L , K , R ](seq : Map [K , Either [L , R ]], leftCombine : (K , L ) => L ): Either [L , Map [K , R ]] =
24
26
Right {
25
- seq.foldLeft(Map .empty[K , R ]) { case (res, a) =>
26
- a match {
27
- case (k, Left (l)) => return Left [L , Map [K , R ]](leftCombine(k, l))
28
- case (k, Right (r)) => res + (k -> r)
29
- }
27
+ seq.foldLeft(Map .empty[K , R ]) {
28
+ case (res, a) =>
29
+ a match {
30
+ case (k, Left (l)) => return Left [L , Map [K , R ]](leftCombine(k, l))
31
+ case (k, Right (r)) => res + (k -> r)
32
+ }
30
33
}
31
34
}
32
- }
33
35
34
- def map [K , R ](seq : Map [K , Either [DynamosParsingError , R ]]): Either [DynamosParsingError , Map [K , R ]] = {
36
+ def map [K , R ](seq : Map [K , Either [DynamosParsingError , R ]]): Either [DynamosParsingError , Map [K , R ]] =
35
37
map[DynamosParsingError , K , R ](seq, (k, l) => DynamosParsingError (s " $k -> ${l.field}" ))
36
- }
37
38
38
39
}
0 commit comments