how do I make a map like the following? it is the...
# functional
d
how do I make a map like the following? it is the result of adding 2 maps together ....
mapA
is a
mapOf<String,AnsiColor>()
and
mapB<String,AnsiColor>
needs to be mapped from
set1<String>
in the way that
mapB
entries are constructed from
set1
String
element to
AnsiColor.GREEN
(this is a constant)
r
Hi @Dalinar, I'm not entirely sure what you are attempting to do, maybe if you try to describe it in code even if it does not compile the intention may be a bit more clear. In whatever case I would start by trying
mapA.toList().zip(mapB.toList()) { //transform here }
or similar
d
my main problem is just that i'm rusty on functional kotlin - maybe you could just suggest some possible extension funs to use and then I could figure out what to do?
I have a map of hardcoded substrings that I assign colors to.. I want to enhance this map with another bunch (set) of strings that all map to the same color - for use with debugging.. so I want to combine this set and the main map together into one big map
so like "abc" to AnsiColor.Blue, "def" to AnsiColor.Red add this with all from set "ghi", "jkl", "mno" they all will use AnsiColor.Green, so that is why we only need a set here - not a map like "ghi" to AnsiColor.Green, "jkl" to AnsiColor.Green, "mno" to AnsiColor.Green
so final map has 5 entries, a Blue, a Red and 3 greens with their respective strings
r
ok, I think I get what you mean now. I will reply in the main channel with a code snippet
d
great, thanks