Ckini.Stream (Ckini v0.1.0) View Source

This module represents a stream data type.

It's usually used to store a stream of substitutions but can also be mapped to other types.

Link to this section Summary

Functions

Concat a stream of stream.

Like concat/1, but interleave a stream of stream instead.

This mplus function is the same implementation used in condi in other miniKanren implementations. It's generally more effective in searching the state tree comparing to those that uses interleave/concat. However, as you can see in the example below, the search order is difficult keep track of.

Link to this section Types

Specs

goal() :: (Ckini.Context.t() -> t(Ckini.Context.t()))

Specs

t() :: t(any())

Specs

t(v) :: nil | %Ckini.Stream{car: v, cdr: t(v)} | (() -> t(v))

Link to this section Functions

Specs

bind_goal(t(Subst.t()), goal()) :: t(Subst.t())

Specs

bind_goals(t(Subst.t()), t(goal())) :: t(Subst.t())

Specs

concat(t(t(a()))) :: t(a())

Concat a stream of stream.

iex> [ ...> [0, 1, 2, 3], ...> [4, 5, 6], ...> [7], ...> [8] ...> ] ...> |> Enum.map(&from_list/1) ...> |> from_list() ...> |> concat() ...> |> to_list() [0, 1, 2, 3, 4, 5, 6, 7, 8]

Specs

concat2(t(a()), t(a())) :: t(a())

Specs

cons(a(), t(a())) :: t(a())

Specs

empty() :: t()

Specs

empty?(t()) :: boolean()

Specs

filter(t(a()), (a() -> boolean())) :: t(a())

Specs

interleave(t(t(a()))) :: t(a())

Like concat/1, but interleave a stream of stream instead.

iex> [ ...> [0, 4, 6, 8], ...> [1, 5, 7], ...> [2], ...> [3] ...> ] ...> |> Enum.map(&from_list/1) ...> |> from_list() ...> |> interleave() ...> |> to_list() [0, 1, 2, 3, 4, 5, 6, 7, 8]

Specs

map(t(a()), (a() -> b())) :: t(b())

Specs

mplus(t(a()), t(a())) :: t(a())

Specs

mplus_many(t(t(a()))) :: t(a())

This mplus function is the same implementation used in condi in other miniKanren implementations. It's generally more effective in searching the state tree comparing to those that uses interleave/concat. However, as you can see in the example below, the search order is difficult keep track of.

You can use condem function to use this implementation.

iex> [ ...> [0, 1, 3, 4], ...> [2, 5, 7], ...> [6, 8], ...> [9] ...> ] ...> |> Enum.map(&from_list/1) ...> |> from_list() ...> |> mplus_many() ...> |> to_list() [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

Specs

new(a(), t(a())) :: t(a())

Specs

rotate1(t(a())) :: t(a())

Specs

singleton(a()) :: t(a())

Specs

snoc(t(a()), a()) :: t(a())

Specs

split(t(a())) :: {a(), t(a())} | nil

Specs

take(t(a()), non_neg_integer()) :: t(a())