I feel like a bit of a n00b because I find the Monoid docs not really helpful in understanding how to use Monoids in Arrow (I use them regularly in other FP programs). I have a
We've put a lot of effort into the docs, but as in many projects, it's the very hardest part. Any help or contribution is always very much appreciated if you have some ideas for improving the docs on
Monoid
.
I'm always happy to help if you have any questions in regards to contributing! So feel free to reach out here or in DM.
👍 1
k
kierans777
03/09/2022, 9:09 AM
Thanks for the reply @simon.vergauwen. Could you please give me an example of how to fold a
List<Map<String, String>>
to a`Map<String, String>` using a Monoid? I don't understand why
Monoid.map
requires an argument.
Copy code
val x = listOf(mapOf("one", "1"), mapOf("two", "2"), mapOf("three", "3"))
val y = ???
// I want y to look like
y = {
"one": "1"
"two": "2"
"three": "3"
}
s
simon.vergauwen
03/09/2022, 9:27 AM
The reason for the argument to
map
is because you need to be able to combine values for duplicated keys.
Copy code
val x = listOf(mapOf("one" to "1"), mapOf("two" to "2"), mapOf("three" to "3"), mapOf("three" to "3"))
val y = x.combineAll(Semigroup.map(Semigroup.string())) // mapOf("one" to "1", "two" to "2", "three" to "33")
k
kierans777
03/09/2022, 9:29 AM
OK, in a statically typed language I can see why you need to do it like that.