Hi, I'm testing arrow-2 now and I've got a little ...
# arrow
m
Hi, I'm testing arrow-2 now and I've got a little problem. I want to create domain aggregate from two value objects (or collect errors from these two) which are eithers already or return a common Error object if anything goes wrong. How should I code flow like this using arrow-2?
Copy code
DObject_1.create()
.zip(DObject_2.create()) { o1, o2 ->
    Aggregate.create(o1,o2)   <-- create returns Either<Error, Aggregate>
}
.flatMap( save(it))  <-- it is Either but i want Aggregate here
p
flatMap into flatMap?
oh, it's a multi-zip
Copy code
DObject_1.create()
  .zip(DObject_2.create(), ::Tuple)
  .flatMap { (a, b) -> // destructured
    Aggregate.create(a,b)
  }.flatMap(::save)
or
Copy code
DObject_1.create()
.zip(DObject_2.create()) { o1, o2 ->
    Aggregate.create(o1,o2)
}
.flatten()
.flatMap(::save)
t
or with dsl
Copy code
either{
    val o1 = DObject_1.create().bind()
    val o2 = DObject_2.create().bind()
    val agg = Aggregate.create(o1, o2).bind()
    agg.save().bind()
}