Eithered

name.rayrobdod.stringContextParserCombinator.typeclass.Eithered
See theEithered companion object
trait Eithered[-A, -B, +Z]

Describes how to represent a result that may be one of two results

Below is example of defining and using a custom Eithered.

import java.io.File
import java.net.URI
import java.util.UUID
import name.rayrobdod.stringContextParserCombinator.Interpolator.idInterpolators._
import name.rayrobdod.stringContextParserCombinator.typeclass.Eithered

given Eithered[File, UUID, URI] with {
 def left(f: File): URI = f.toURI
 def right(id: UUID): URI = new URI("urn", "uuid:" + id.toString, null)
}

val uuidParser:Interpolator[UUID] = ofType[UUID]
val fileParser:Interpolator[File] = ofType[File]
val p:Interpolator[URI] = (fileParser:Interpolator[File]) orElse (uuidParser:Interpolator[UUID]) // using Eithered[File, UUID, URI]

p.interpolate(StringContext("", ""), new File("/tmp") :: Nil) // `file:///tmp`: URI
p.interpolate(StringContext("", ""), UUID.randomUUID() :: Nil) // `urn:uuid:429bf7eb-650e-4f8c-be3f-1420913a6bd7`: URI

Type parameters

A

the first choice

B

the second choice

Z

the result container

Attributes

See also
Companion
object
Source
Eithered.scala
Graph
Supertypes
class Object
trait Matchable
class Any
Known subtypes
trait BiEithered[Expr, A, B, Z]

Members list

Value members

Abstract methods

def left(elem: A): Z

Attributes

Source
Eithered.scala
def right(elem: B): Z

Attributes

Source
Eithered.scala