Set.single()

Creates a Set containing a single provided element.

Signature

Set.single(element: A): Set<A>

Description

The Set.single() method returns a Set containing a single element. The element is passed to the method as an argument.

You can use streams to track changes to a Set containing a single document. These streams are only sent events when the document changes.

You typically use Set.single() to create a Set from a Document for a document stream.

Parameters

Parameter Type Required Description

element

Any

Yes

Value for the returned Set's element.

Return value

Type Description

Set

Set containing the provided element.

Examples

The following query creates a Set from a single document.

let product = Product.byId(392174614626697728)!
Set.single(product)

Response:

{
  data: [
    {
      id: "392997052451127332",
      coll: Product,
      ts: Time("2024-03-21T19:40:45.430Z"),
      name: "cups",
      description: "Translucent 9 Oz, 100 ct",
      ...
    }
  ]
}

You can call changesOn() or toStream() on the Set to create a document stream.

let product = Product.byId(392174614626697728)!
Set.single(product).toStream()

The query returns a stream token.

"g9WD1YPG..."

Is this article helpful? 

Tell Fauna how the article can be improved:
Visit Fauna's forums or email docs@fauna.com

Thank you for your feedback!