PathSegment

trait PathSegment[T, +A] extends UrlPart[T, A]

Represents a part of the path string of an URL, containing an information of type T, or an error of type A.

Represents a part of the path string of an URL, containing an information of type T, or an error of type A.

Type Params
A

type of the error that this PathSegment produces on "illegal" url paths.

T

type represented by this PathSegment

Companion
object
trait UrlPart[T, A]
class Object
trait Matchable
class Any

Value members

Abstract methods

def createSegments(t: T): List[Segment]

Generate a list of segments representing the argument t.

Generate a list of segments representing the argument t.

matchSegments and createSegments should be (functional) inverse of each other. That is, this.matchSegments(this.createSegments(t)) == Right(PathMathOutput(t, Nil))

def matchSegments(segments: List[Segment]): Either[A, PathMatchOutput[T]]

Tries to match the list of urldsl.vocabulary.Segments to create an instance of T. If it can not, it returns an error indicating the reason of the failure. If it could, it returns the value of T, as well as the list of unused segments.

Tries to match the list of urldsl.vocabulary.Segments to create an instance of T. If it can not, it returns an error indicating the reason of the failure. If it could, it returns the value of T, as well as the list of unused segments.

Value Params
segments

The list of urldsl.vocabulary.Segment to match this path segment again.

Returns

The "de-serialized" element with unused segment, if successful.

Example

For example, a segment that matches simply a String in the first segment, when giving segments like List(Segment("hello"), Segment("3")) will return Right(PathMatchOutput("hello", List(Segment("3")))

Concrete methods

final def /[U, A1 >: A](that: PathSegment[U, A1])(ev: Tupler[T, U]): PathSegment[Out, A1]

Concatenates this urldsl.language.PathSegment with that one, "tupling" the types with the Tupler rules.

Concatenates this urldsl.language.PathSegment with that one, "tupling" the types with the Tupler rules.

final def ?[ParamsType, QPError](params: QueryParameters[ParamsType, QPError]): PathSegmentWithQueryParams[T, A, ParamsType, QPError]
final def as[U](codec: Codec[T, U]): PathSegment[U, A]

Casts this PathSegment to the new type U. Note that the urldsl.vocabulary.Codec must be an exception-free bijection between T and U (or at least an embedding, if you know that you are doing).

Casts this PathSegment to the new type U. Note that the urldsl.vocabulary.Codec must be an exception-free bijection between T and U (or at least an embedding, if you know that you are doing).

final def as[U](fromTToU: T => U, fromUToT: U => T): PathSegment[U, A]

Casts this PathSegment to the new type U. The conversion functions should form an exception-free bijection between T and U (or at least an embedding, if you know that you are doing).

Casts this PathSegment to the new type U. The conversion functions should form an exception-free bijection between T and U (or at least an embedding, if you know that you are doing).

final def createPart(t: T, encoder: UrlStringGenerator): String
def createPath(t: T, encoder: UrlStringGenerator): String

Concatenates the segments generated by createSegments

Concatenates the segments generated by createSegments

final def createPath(ev: Unit =:= T): String

Sugar when T =:= Unit

Sugar when T =:= Unit

final def createPath(encoder: UrlStringGenerator)(ev: Unit =:= T): String
final def createSegments(ev: Unit =:= T): List[Segment]

Sugar when T =:= Unit

Sugar when T =:= Unit

final def filter[A1 >: A](predicate: T => Boolean, error: List[Segment] => A1): PathSegment[T, A1]

Adds an extra satisfying criteria to the de-serialized output of this urldsl.language.PathSegment.

Adds an extra satisfying criteria to the de-serialized output of this urldsl.language.PathSegment.

The new de-serialization works as follows:

  • if the initial de-serialization fails, then it returns the generated error
  • otherwise, if the de-serialized element satisfies the predicate, then it returns the element
  • if the predicate is false, generates the given error by feeding it the segments that it tried to match.

This can be useful in, among others, two scenarios:

  • enforce bigger restriction on a segment (e.g., from integers to positive integer, regex match...)
  • in a multi-part segment, ensure consistency between the different component (e.g., a range of two integers that should not be too large...)
final def filter(predicate: T => Boolean)(ev: A <:< DummyError): PathSegment[T, DummyError]

Sugar for when A =:= DummyError

Sugar for when A =:= DummyError

final def ignore(default: => T): PathSegment[Unit, A]

Matches using this PathSegment, and then forgets its content. Uses the default value when creating the path to go back.

Matches using this PathSegment, and then forgets its content. Uses the default value when creating the path to go back.

def matchPath(path: String, decoder: UrlStringDecoder): Either[A, T]
def matchRawUrl(url: String, urlStringParserGenerator: UrlStringParserGenerator): Either[A, T]

Matches the given raw url using the given urldsl.url.UrlStringParserGenerator for creating a urldsl.url.UrlStringParser.

Matches the given raw url using the given urldsl.url.UrlStringParserGenerator for creating a urldsl.url.UrlStringParser.

This method doesn't return the information about the remaining unused segments. The thought leading to this is that urldsl.vocabulary.PathMatchOutput are supposed to be internal mechanics, while this method is supposed to be the exposed interface of this urldsl.language.PathSegment.

Value Params
url

the url to parse. It has to be a well formed URL, otherwise this could raise an exception, depending on the provided urldsl.url.UrlStringParserGenerator.

urlStringParserGenerator

the urldsl.url.UrlStringParserGenerator used to create the urldsl.url.UrlStringParser that will actually parse the url to create the segments. The default one is usually a good choice. It has different implementations in JVM and JS, but they should behave the same way.

Returns

the output contained in the url, or the error if something fails.

final def provide[A1 >: A](t: T)(pathMatchingError: PathMatchingError[A1], printer: Printer[T]): PathSegment[Unit, A1]

Forgets the information contained in the path parameter by injecting one. This turn this "dynamic" PathSegment into a fix one.

Forgets the information contained in the path parameter by injecting one. This turn this "dynamic" PathSegment into a fix one.

final def withFragment[FragmentType, FragmentError](fragment: Fragment[FragmentType, FragmentError]): PathQueryFragmentRepr[T, A, Unit, Nothing, FragmentType, FragmentError]

Associates this PathSegment with the given Fragment in order to match raw urls satisfying both conditions, and returning the outputs from both.

Associates this PathSegment with the given Fragment in order to match raw urls satisfying both conditions, and returning the outputs from both.

The query part of the url will be ignored (and will return Unit).

final def ||[U, A1 >: A](that: PathSegment[U, A1]): PathSegment[Either[T, U], A1]

Builds a PathSegment that first tries to match with this one, then tries to match with that one. If both fail, the error of the second is returned (todo[behaviour]: should that change?)

Builds a PathSegment that first tries to match with this one, then tries to match with that one. If both fail, the error of the second is returned (todo[behaviour]: should that change?)

Inherited methods

final def createPart(ev: Unit =:= T): String

Sugar when T =:= Unit

Sugar when T =:= Unit

Inherited from
UrlPart
final def createPart(encoder: UrlStringGenerator)(ev: Unit =:= T): String

Sugar when T =:= Unit

Sugar when T =:= Unit

Inherited from
UrlPart