No matching definitions.

tur/unique

stdlib/unique.tur

uniqueness-type patterns (with-unique, consume, replace).

Since: UT3

defmacro

with-unique

(with-unique [binding & body])

scope a uniquely-owned binding over a body.

bindinga two-element form `[name init]`: the binding name and its
uniquely-owned initializer
bodyone or more expressions evaluated with `name` in scope

The value of the last body expression.

(with-unique [u (make-ref 42)]   ; u : ^unique
    (use-once u))                  ; consumed exactly once

Since: UT3

defn

consume

(consume [A B])

thread a unique value through a single transforming call.

xthe uniquely-owned value to consume
fa function that takes ownership of `x` and returns a result

The result of `(f x)`.

(consume buf buf-finish)   ; => the result of (buf-finish buf)

Since: UT3

defn

replace

(replace [A])

displace a unique value, returning the old one.

oldthe uniquely-owned value being displaced
newthe replacement value, consumed into the swap

The displaced `old` value, for the caller to inspect or drop.

(let [displaced (replace current next)]
    (drop! displaced))   ; old `current` handed back for disposal

Since: UT3