Writer

smithy4s.codecs.Writer
See theWriter companion object
trait Writer[-In, +Out, -A]

An abstraction that codifies the notion of writing a piece of data into an output, provided some contextual information.

This has two input channels:

  • one for contextual information (In)
  • one for the actual data (A)

This is particularly useful for http requests/responses, where different subsets of data have a different impact on different locations of the http message : some fields may impact headers, some fields may impact the http body, other things that are driven from static information (smithy traits) may lead to a transformation of the message. In this situation, the Input and Output channels are of the same type.

Having the ability to decompose the notion of encoding a piece of data into different writers that can be composed together is powerful and helps centralising some complexity in third-party agnostic code.

Type parameters

A:

the type of data that is being written into the output channel

In

: some input channel used as context to write data. When set to Any, the implication is that the data produces some output on its own

Out:

the output channel in which the data is written.

Attributes

Companion
object
Graph
Supertypes
class Object
trait Matchable
class Any
Self type
Writer[In, Out, A]

Members list

Value members

Abstract methods

def write(input: In, a: A): Out

Symbolises the action of writing some content A into an output Out, provided some context In

Symbolises the action of writing some content A into an output Out, provided some context In

Attributes

Concrete methods

final def andThen[Out0](f: Out => Out0): Writer[In, Out0, A]

Transforms the Output type

Transforms the Output type

Attributes

final def compose[In0](f: In0 => In): Writer[In0, Out, A]

Transforms the context Input type

Transforms the context Input type

Attributes

final def contramap[B](f: B => A): Writer[In, Out, B]

Contramap the data which this writer works. The writer is a contravariant-functor on A.

Contramap the data which this writer works. The writer is a contravariant-functor on A.

Attributes

def encode[In0 <: In](a: A)(implicit ev: Any =:= In0): Out

When the data A is sufficient to produce the output, anything can be used as a context input. Therefore, traditional encoders (like Json/Xml) can be modelled as Writers with type In == Any

When the data A is sufficient to produce the output, anything can be used as a context input. Therefore, traditional encoders (like Json/Xml) can be modelled as Writers with type In == Any

This method is a short-hand for encoding the data without the caller forced to pass a dummy input.

Attributes

def pipe[Out0, A0 <: A](other: Writer[Out, Out0, A0]): Writer[In, Out0, A0]

Connects this writer's output channel to the contextual input channel of another writer.

Connects this writer's output channel to the contextual input channel of another writer.

Attributes

def pipeData[Message <: In, Out0 >: Out](other: Writer[Message, Message, Out]): Writer[Message, Message, A]

Connects this writer's output channel to the data channel of another writer. This is useful for connecting an encoder into a larger writer.

Connects this writer's output channel to the data channel of another writer. This is useful for connecting an encoder into a larger writer.

Attributes

final def toEncoder(in: In): Writer[Any, Out, A]

Transforms a writer into an Encoder by supplying an initial value.

Transforms a writer into an Encoder by supplying an initial value.

Attributes