NLdoc.Spec (NLdoc.Spec v3.1.1)

View Source

This module defines the Ecto schema for the NLdoc spec objects.

Summary

Functions

Recursively find the first spec object to match the given predicate, or return the given default value.

Returns the version of the NLdoc API spec that the NLdoc.Spec library implements.

Types

Functions

blockquote_children()

descriptors()

document_children()

find_recursive(object, predicate)

@spec find_recursive(object() | [object()], (object() -> boolean())) :: object() | nil

Recursively find the first spec object to match the given predicate, or return the given default value.

This function performs a depth-first search through the children of a spec object or list of spec objects, and returns the first spec object for which the predicate returns true.

Examples

iex> alias NLdoc.Spec.{Paragraph, Text}
iex> NLdoc.Spec.find_recursive(
...>   [%Text{text: "1"}, %Text{text: "2"}],
...>   fn object -> object.text === "2" end
...> )
%Text{text: "2"}
iex> NLdoc.Spec.find_recursive(
...>   [%Paragraph{children: [%Text{text: "1"}, %Text{text: "2"}]}, %Paragraph{children: [%Text{text: "3"}, %Text{text: "4"}]}],
...>   fn
...>     %Text{text: text} -> text |> String.to_integer() |> rem(2) === 0
...>     _ -> false
...>   end
...> )
%Text{text: "2"}
iex> NLdoc.Spec.find_recursive([], fn _ -> true end)
nil
iex> NLdoc.Spec.find_recursive([], fn _ -> true end, "test")
"test"
iex> NLdoc.Spec.find_recursive([%Text{text: "1"}, %Text{text: "2"}], fn _ -> false end)
nil
iex> NLdoc.Spec.find_recursive([%Text{text: "1"}, %Text{text: "2"}], fn _ -> false end, "default")
"default"

find_recursive(elements, predicate, default)

@spec find_recursive([object()], (object() -> boolean()), default) ::
  object() | default
when default: var

objects()

paragraph_children()

text_styling()

@spec text_styling() :: [text_style()]

version()

@spec version() :: String.t()

Returns the version of the NLdoc API spec that the NLdoc.Spec library implements.