Petr Makagon
10/26/2020, 2:58 AMalbertosh
10/26/2020, 9:34 AMval SE = Nel.semigroup<MyError>()
val ap = ValidatedNel.applicative(SE)
val validated = list.sequence(ap).fix()
?Scott Christopher
10/26/2020, 9:38 AMValidatedNel<MyError, List<Unit>>?Scott Christopher
10/26/2020, 9:39 AMList<Unit> is probably as useful as a Unit though.Scott Christopher
10/26/2020, 9:40 AMlist.reduce { a, b ->
a.combineK(Nel.semigroup(), b)
}Scott Christopher
10/26/2020, 9:42 AMcombineK won't collect validation errors, if either of them are successful.Scott Christopher
10/26/2020, 9:42 AMUnit and use combine rather than combineK.Scott Christopher
10/26/2020, 9:44 AMobject MonoidUnit : Monoid<Unit> {
override fun Unit.combine(b: Unit) = this
override fun empty() = Unit
}
list.reduce { a, b ->
a.combine(Nel.semigroup(), MonoidUnit, b)
}albertosh
10/26/2020, 11:00 AMWouldn’t that result in aIt will, yes. If you need a?ValidatedNel<MyError, List<Unit>>
Unit result you could go with the Unit monoid or just add a .map { Unit }Petr Makagon
10/26/2020, 3:49 PM