does anyone know how to fix this syntax error? I w...
# announcements
h
does anyone know how to fix this syntax error? I want to alter the structure of the first map so that it returns
List<Pair<PublisherMessage, deviceType>>
. It currrently only returns
emailMesssages: List<MessageSender>
s
simplified snippets are preferred
I don’t know what a
phoneType
or a
deviceType
is, and there’s not enough context from the screenshot to really divine what the transform looks like
but the problem ostensibly looks like that second, inner map constructing
MessageSender
objects
or at least, if it’s not the “problem”, it’s where you would want to change your logic to build
Pair<PublisherMessage, deviceType>
instances
h
thanks @Shawn second inner map did you mean the flatmap bit?
s
lines 22-26
you should probably try to sort out what your starting and ending types are for this transform first, then go from there
h
Could you please provide an example as im quite lost
i
Currently
map
return the Pair because map lreturns the last expression and currently you have ony one expression that creates Pair object. If you want to return something else you could just wrap it in the list
Copy code
.map { pair ->
listOf(Pair(...))
}
h
here is the snippet
s
do you want the second pair element to be a
Pair<List<MessageSender, String>>
?
h
yes
@Shawn because the class
data class MyMessage(val environment: String, val phoneType: String, val phoneId: String)
contains
phoneType
which is just a String.
s
Copy code
.map { (error, messages) ->
  error to messages.map { myMessage -> 
    MessageSender(message = myMessage.environment) to myMessage.phoneType
  }
}
is perhaps what you want
h
let me try that
@Shawn thanks that works but now how can I reference that second pair (the String) and put it in the my MessageIndex constructor like this
s
I am increasingly less confident that this is all what you want, but you can use
it
as a reference to the element you’re grouping by
h
@Shawn thanks tried that now getting one more error
s
you have a type mismatch
you said you wanted that
List<Pair<MessageSender, String>>
, so we got that working
if you need a
List<MessageSender>
then, you need to apply a different transform or maybe extract the `MessageSender`s out of those pairs
I have no clue what MessageIndex is, how it plays into your application, etc
past this point it’s not really kotlin-related
h
okay thanks I managed to get rid of the syntax error by changing the signature of
handleMessages(messages: Map<MessageIndex, List<Pair<MessageSender, String>>>)