Ludwig.NodeStream

This module allows you to work with the ‘NodeStream’. This is an advanced Ludwig concept that holds the entire output. By having access to the entire output, it is possible to write validations across values and types.

Module Members

getNodes

(Function)

Get all present nodes.

Type Signature

 fun (NodeStream) -> List<Node<Anything>>
Argument: ns
Type: NodeStream
Returns:
Type: List<Node<Anything>>

getTags

(Function)

Get all present tags. This can be used to implement a whitelist: simply check all entries in this list against a set of blessed tags.

Type Signature

 fun (NodeStream) -> List<String>
Argument: ns
Type: NodeStream
Returns:
Type: List<String>

lookupNodeByValue

(Function)

If you only have the ‘value’ of a ‘Node’, you can use this to look up other details such as the ID and the tag.

Type Signature

 fun (NodeStream, a) -> Optional<Node<a>>
Argument: ns
Type: NodeStream
Argument: value
Type: a
Returns:
Type: Optional<Node<a>>

reachableByIds

(Function)

This function considers the NodeStream as a graph and functions relatively similar to many garbage-collecting algorithms.

Given a set of “root” IDs for nodes, it will give you all nodes than can be reached by following references from these root nodes.

Type Signature

 fun (NodeStream, List<String>) -> Dictionary<Node<Anything>>
Argument: ns

The NodeStream

Type: NodeStream

Argument: ids

The set of root nodes to start with.

Type: List<String>

Returns:

A dictionary of reachable nodes. The dictionary is indexed by node IDs and contains the root nodes as well.

Type: Dictionary<Node<Anything>>

unsafeAddMetaAnnotation

(Function)

This function allows you put arbitrary annotations on Ludwig resources (sum type values). These annotations will then be present in the final NodeStream.

These annotations are similar to annotations in ludwig files, e.g.: @mutable, @proto(2), but re-ified on Ludwig values and tracked during execution.

Annotations can be transient or not. If an annotation is transient, it is lost when making updates to the value (e.g. using the with statement). If it is not transient, it is kept when updating the value.

Type Signature

 fun { name: String,
       arguments: Optional<List<String>>,
       transient: Optional<Bool>,
       value: a} -> a
Argument: name

Name of the annotation

Type: String

Argument: arguments

Arguments of the annotation

Type: Optional<List<String>>

Argument: transient

Whether this is a transient annotation. Defaults to False

Type: Optional<Bool>

Argument: value

Value to add the annotation to

Type: a

Returns:

The updated value, with the annotation set

Type: a

unsafeCopyAnnotations

(Function)

This function allows you take all annotations on src and add them to dst. This creates a new dst value.

Note that transient annotations (see unsafeAddMetaAnnotation) are not copied.

Type Signature

 fun (a, b) -> b
Argument: src

Source of the annotations.

Type: a

Argument: dst

Destination to copy the annotations to.

Type: b

Returns:
Type: b

unsafeGetNodesByTag

(Function)

Get all nodes of a certain type (tag) from the ‘NodeStream’.

The tag is the concatenation of the module name and the type name. This is the same as the “fully qualified” type name.

Example:

subnets: unsafeGetNodesByTag(ns, 'Fugue.Core.AWS.EC2.Subnet')

Type Signature

 fun (NodeStream, String) -> List<Node<a>>
Argument: ns

The nodestream

Type: NodeStream

Argument: tag

Tag of the types you want to obtain

Type: String

Returns:

List of nodes of the requested type

Type: List<Node<a>>

unsafeLookupNodeById

(Function)

If you only have the ‘id’ of a ‘Node’, you can use this to look up the actual value.

Type Signature

 fun (NodeStream, String) -> Optional<Node<a>>
Argument: ns
Type: NodeStream
Argument: id
Type: String
Returns:
Type: Optional<Node<a>>

valuesEqual

(Function)

This function checks that both x and y are node values, and that they are in fact the same node. You can use this to compare the value of two Nodes or to compare arbitrary types that are supposed to be nodes.

If x or y are not nodes, then this function will return False.

Example:

foo:
  let subnet: Subnet.new {...}
  NodeStream.valuesEqual(subnet, subnet)  # => True

Note a node:

bar: NodeStream.valuesEqual(1, 1)  # => False

Type Signature

 fun (a, a) -> Bool
Argument: x

First node to compare

Type: a

Argument: y

Second node to compare

Type: a

Returns:

Whether or not the two nodes are one and the same

Type: Bool

Node

(Type)

type Node<a>:
  id: String
  tag: String
  value: a

A ‘Node’ is a single entry in the ‘NodeStream’.

Record {

Field: id
Type: String
Field: tag
Type: String
Field: value
Type: a

}

NodeStream

(Type)

type opaque NodeStream

The ‘NodeStream’ is an advanced Ludwig concept that holds the entire output of the compiler. It is possible to write validations for this type.