Skip to content

Commit

Permalink
Improve xml consumer syntax, introduce missing extension (#246)
Browse files Browse the repository at this point in the history
improve xml consumer syntax, introduce missing extension
  • Loading branch information
majk-p authored Feb 28, 2023
1 parent e04b8f2 commit 256b463
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@

package com.ocadotechnology.pass4s.phobos

import cats.MonadError
import cats.MonadThrow
import cats.syntax.all._
import com.ocadotechnology.pass4s.core.Destination
import com.ocadotechnology.pass4s.core.Message
import com.ocadotechnology.pass4s.core.Message.Payload
import com.ocadotechnology.pass4s.core.groupId.GroupIdMeta
import com.ocadotechnology.pass4s.core.groupId.MessageGroup
import com.ocadotechnology.pass4s.kernel.Consumer
Expand Down Expand Up @@ -100,4 +102,14 @@ object syntax {
consumer.mapM(XmlDecoder[A].decode(_).liftTo[F])
}

implicit final class ConsumeXmlGenericMessageSyntax[F[_], A](private val consumer: Consumer[F, A]) {

def asXmlConsumer[B: XmlDecoder](
implicit M: MonadError[F, _ >: ru.tinkoff.phobos.decoding.DecodingError],
ev: A <:< Payload
): Consumer[F, B] =
consumer.mapM(msg => XmlDecoder[B].decode(msg.text).liftTo[F])

}

}

0 comments on commit 256b463

Please sign in to comment.