shampoo.yaml

package shampoo.yaml

Members list

Type members

Classlikes

object Yaml

Provides YAML utilities.

Provides YAML utilities.

import scala.language.implicitConversions

import shampoo.yaml.{ *, given }

// Create YAML mapping
val user = Yaml.map("id" -> 1000, "name" -> "lupita")

// Create YAML sequence
val info = Yaml.seq(user, "/home/lupita", 1024)

// Load YAML
val root = Yaml.load("{ id: 0, name: root }")

case class User(id: Int, name: String)

given userRepresenter: YamlRepresenter[User] =
  user => Yaml.map("id" -> user.id, "name" -> user.name)

// Represent value to YAML
val nobody = Yaml.toYaml(User(65534, "nobody"))

// Dump YAML to stdout
Yaml.dump(nobody, System.out)

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
Yaml.type
sealed trait YamlBoolean extends YamlScalar

Defines YAML boolean.

Defines YAML boolean.

Attributes

Companion
object
Supertypes
trait YamlScalar
trait YamlNode
class Object
trait Matchable
class Any
object YamlBoolean

Provides YAML boolean constructor.

Provides YAML boolean constructor.

Attributes

Companion
trait
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type
sealed trait YamlCollection extends YamlNode

Defines YAML collection.

Defines YAML collection.

Attributes

Supertypes
trait YamlNode
class Object
trait Matchable
class Any
Known subtypes

Assumes either YAML mapping or YAML sequence.

Assumes either YAML mapping or YAML sequence.

Attributes

See also
Note

A collection facade is created by conversion only.

Supertypes
trait YamlSequence
trait YamlMapping
trait YamlNode
class Object
trait Matchable
class Any
Show all
@FunctionalInterface
trait YamlConstructor[T]

Defines YAML constructor.

Defines YAML constructor.

import scala.language.implicitConversions

import shampoo.yaml.{ *, given }

case class User(id: Int, name: String)

// Define how to construct User from YAML
given YamlConstructor[User] =
  yaml => User(yaml("id"), yaml("name"))

val yaml = Yaml.load("{ id: 1000, name: lupita }")

// Construct and verify
val user = yaml.as[User]
assert(user.id == 1000)
assert(user.name == "lupita")

Attributes

See also
Supertypes
class Object
trait Matchable
class Any
class YamlException(message: String, cause: Throwable) extends RuntimeException

Defines YAML exception.

Defines YAML exception.

Value parameters

cause

underlying cause

message

detail message

Attributes

Constructor

Creates exception with message and cause.

Supertypes
class RuntimeException
class Exception
class Throwable
trait Serializable
class Object
trait Matchable
class Any
Show all
sealed trait YamlMapping extends YamlCollection

Defines YAML mapping.

Defines YAML mapping.

Attributes

See also
Supertypes
trait YamlNode
class Object
trait Matchable
class Any
Known subtypes

Defines YAML mapping builder.

Defines YAML mapping builder.

import scala.language.implicitConversions

import shampoo.yaml.{ *, given }

val user = YamlMappingBuilder()
  .add("id", 1000)
  .add("name", "lupita")
  .add("groups", Set("lupita", "sudoer"))
  .toYamlMapping()

assert { user("id").as[Int] == 1000 }
assert { user("name").as[String] == "lupita" }
assert { user("groups").as[Set[String]] == Set("lupita", "sudoer") }

Attributes

See also
Supertypes
class Object
trait Matchable
class Any
sealed trait YamlNode

Defines YAML node.

Defines YAML node.

Attributes

Supertypes
class Object
trait Matchable
class Any
Known subtypes
trait YamlMapping
trait YamlSequence
trait YamlScalar
trait YamlBoolean
object YamlNull.type
trait YamlNumber
trait YamlString
Show all
case object YamlNull extends YamlScalar

Defines YAML null.

Defines YAML null.

Attributes

Supertypes
trait Singleton
trait Product
trait Mirror
trait Serializable
trait Product
trait Equals
trait YamlScalar
trait YamlNode
class Object
trait Matchable
class Any
Show all
Self type
YamlNull.type
sealed trait YamlNumber extends YamlScalar

Defines YAML number.

Defines YAML number.

Attributes

Companion
object
Supertypes
trait YamlScalar
trait YamlNode
class Object
trait Matchable
class Any
object YamlNumber

Provides YAML number constructor.

Provides YAML number constructor.

Attributes

Companion
trait
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type
YamlNumber.type
@FunctionalInterface
trait YamlRepresenter[T]

Defines YAML representer.

Defines YAML representer.

import scala.language.implicitConversions

import shampoo.yaml.{ *, given }

case class User(id: Int, name: String, groups: Seq[String])

// Define how to represent YAML from User
given YamlRepresenter[User] =
  user => Yaml.map("id" -> user.id, "name" -> user.name)

val user = User(1000, "lupita")

// Represent and verify
val yaml = Yaml.toYaml(user)
assert(yaml.getInt("id") == 1000)
assert(yaml.getString("name") == "lupita")

Attributes

See also
Supertypes
class Object
trait Matchable
class Any
sealed trait YamlScalar extends YamlNode

Defines YAML scalar.

Defines YAML scalar.

Attributes

Supertypes
trait YamlNode
class Object
trait Matchable
class Any
Known subtypes
trait YamlBoolean
object YamlNull.type
trait YamlNumber
trait YamlString
sealed trait YamlSequence extends YamlCollection

Defines YAML sequence.

Defines YAML sequence.

Attributes

See also
Supertypes
trait YamlNode
class Object
trait Matchable
class Any
Known subtypes

Defines YAML sequence builder.

Defines YAML sequence builder.

import scala.language.implicitConversions

import shampoo.yaml.{ *, given }

val user = YamlSequenceBuilder()
  .add(1000)
  .add("lupita")
  .add(Set("lupita", "sudoer"))
  .toYamlSequence()

assert { user(0).as[Int] == 1000 }
assert { user(1).as[String] == "lupita" }
assert { user(2).as[Set[String]] == Set("lupita", "sudoer") }

Attributes

See also
Supertypes
class Object
trait Matchable
class Any
sealed trait YamlString extends YamlScalar

Defines YAML string.

Defines YAML string.

Attributes

Companion
object
Supertypes
trait YamlScalar
trait YamlNode
class Object
trait Matchable
class Any
object YamlString

Provides YAML string constructor.

Provides YAML string constructor.

Attributes

Companion
trait
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type
YamlString.type

Givens

Givens

given arrayRepresenter[T](using representer: YamlRepresenter[T]): YamlRepresenter[Array[T]]

Represents Array to YamlSequence.

Represents Array to YamlSequence.

Attributes

Constructs BigDecimal from YamlNumber.

Constructs BigDecimal from YamlNumber.

Attributes

Represents BigDecimal to YamlNumber.

Represents BigDecimal to YamlNumber.

Attributes

Constructs BigInt from YamlNumber.

Constructs BigInt from YamlNumber.

Attributes

Represents BigInt to YamlNumber.

Represents BigInt to YamlNumber.

Attributes

Constructs Boolean from YamlBoolean.

Constructs Boolean from YamlBoolean.

Attributes

Represents Boolean to YamlBoolean.

Represents Boolean to YamlBoolean.

Attributes

given collectionConstructor[T, M[T]](using constructor: YamlConstructor[T])(using factory: Factory[T, M[T]]): YamlConstructor[M[T]]

Constructs collection from YamlSequence.

Constructs collection from YamlSequence.

Attributes

Constructs Double from YamlNumber.

Constructs Double from YamlNumber.

Attributes

Represents Double to YamlNumber.

Represents Double to YamlNumber.

Attributes

given eitherConstructor[A, B](using left: YamlConstructor[A])(using right: YamlConstructor[B]): YamlConstructor[Either[A, B]]

Constructs Either from YamlNode.

Constructs Either from YamlNode.

Attributes

given eitherRepresenter[A, B, M <: (Either)](using left: YamlRepresenter[A])(using right: YamlRepresenter[B]): YamlRepresenter[M[A, B]]

Represents Either to YamlNode.

Represents Either to YamlNode.

Attributes

given failureRepresenter: YamlRepresenter[Failure[_]]

Represents Failure to YamlNull.

Represents Failure to YamlNull.

Attributes

Constructs Float from YamlNumber.

Constructs Float from YamlNumber.

Attributes

Represents Float to YamlNumber.

Represents Float to YamlNumber.

Attributes

Constructs Int from YamlNumber.

Constructs Int from YamlNumber.

Attributes

Represents Int to YamlNumber.

Represents Int to YamlNumber.

Attributes

given interableRepresenter[T, M <: (Iterable)](using representer: YamlRepresenter[T]): YamlRepresenter[M[T]]

Represents Iterable to YamlSequence.

Represents Iterable to YamlSequence.

Attributes

given leftRepresenter[T](using representer: YamlRepresenter[T]): YamlRepresenter[Left[T, _]]

Represents Left to YamlNode.

Represents Left to YamlNode.

Attributes

Constructs Long from YamlNumber.

Constructs Long from YamlNumber.

Attributes

Represents Long to YamlNumber.

Represents Long to YamlNumber.

Attributes

given mapConstructor[T, M <: ([T] =>> Map[String, T])](using constructor: YamlConstructor[T])(using factory: Factory[(String, T), M[T]]): YamlConstructor[M[T]]

Converts YamlNode to Map.

Converts YamlNode to Map.

Attributes

given mapRepresenter[T, M <: ([T] =>> Map[String, T])](using representer: YamlRepresenter[T]): YamlRepresenter[M[T]]

Represents Map to YamlMapping.

Represents Map to YamlMapping.

Attributes

given noneRepresenter: YamlRepresenter[None.type]

Represents None to YamlNull.

Represents None to YamlNull.

Attributes

given optionConstructor[T](using constructor: YamlConstructor[T]): YamlConstructor[Option[T]]

Constructs Option from YamlNode.

Constructs Option from YamlNode.

Attributes

given optionRepresenter[T, M <: (Option)](using representer: YamlRepresenter[T]): YamlRepresenter[M[T]]

Represents Some to YamlNode or returns YamlNull if None.

Represents Some to YamlNode or returns YamlNull if None.

Attributes

given rightRepresenter[T](using representer: YamlRepresenter[T]): YamlRepresenter[Right[_, T]]

Represents Right to YamlNode.

Represents Right to YamlNode.

Attributes

Constructs String from YamlString.

Constructs String from YamlString.

Attributes

Represents String to YamlString.

Represents String to YamlString.

Attributes

given tryConstructor[T](using constructor: YamlConstructor[T]): YamlConstructor[Try[T]]

Constructs Try from YamlNode.

Constructs Try from YamlNode.

Attributes

given tryRepresenter[T, M <: (Try)](using representer: YamlRepresenter[T]): YamlRepresenter[M[T]]

Represents Success to YamlNode or returns YamlNull if Failure.

Represents Success to YamlNode or returns YamlNull if Failure.

Attributes

Casts YamlNode to YamlBoolean.

Casts YamlNode to YamlBoolean.

Attributes

given yamlConstructorConversion[T](using constructor: YamlConstructor[T]): Conversion[YamlNode, T]

Applies conversion using YamlConstructor.

Applies conversion using YamlConstructor.

Attributes

Returns YamlNode as is.

Returns YamlNode as is.

This constructor is required to perform actions such as the following:

import scala.language.implicitConversions

import shampoo.yaml.{ Yaml, YamlNode, given }

val yaml = Yaml.map("values" -> Yaml.seq("abc", 123, true))

// Requires yamlNodeConstructor
val list = yaml("values").as[List[YamlNode]]

Attributes

Casts YamlNode to YamlNull.

Casts YamlNode to YamlNull.

Attributes

Casts YamlNode to YamlNumber.

Casts YamlNode to YamlNumber.

Attributes

Casts YamlNode to YamlMapping.

Casts YamlNode to YamlMapping.

Attributes

given yamlRepresenterConversion[T](using representer: YamlRepresenter[T]): Conversion[T, YamlNode]

Applies conversion using YamlRepresenter.

Applies conversion using YamlRepresenter.

Attributes

Casts YamlNode to YamlSequence.

Casts YamlNode to YamlSequence.

Attributes

Casts YamlNode to YamlString.

Casts YamlNode to YamlString.

Attributes

Converts YamlNode to YamlCollectionFacade.

Converts YamlNode to YamlCollectionFacade.

Attributes

Extensions

Extensions

extension (yaml: YamlNode)
def \(key: String): YamlNode

Gets value in YAML mapping.

Gets value in YAML mapping.

Value parameters

key

mapping key

Attributes

Throws
ClassCastException

if not YamlMapping

def \(index: Int): YamlNode

Gets value in YAML sequence.

Gets value in YAML sequence.

Value parameters

index

sequence index

Attributes

Throws
ClassCastException

if not YamlSequence

def \\(key: String): Seq[YamlNode]

Collects values with given key in traversed collections.

Collects values with given key in traversed collections.

import shampoo.yaml.{ Yaml, \\, given }

val yaml = Yaml.load("""
 node:
   name: localhost
   users:
     - id: 0
       name: root
     - id: 1000
       name: lupita
""")

val names = (yaml \\ "name").map(_.as[String])

assert { names == Seq("localhost", "root", "lupita") }

Value parameters

key

mappings key

Attributes