PtcRunner.Lisp.Runtime.Collection.Normalize (PtcRunner v0.10.1)

Copy Markdown View Source

Predicate and collection normalization helpers for collection operations.

Collapses the combinatorial explosion of pred types x collection types into two reusable normalization functions.

Summary

Functions

Convert string to list of graphemes.

Normalize a key/function to a 1-arity value-extracting function.

Normalize a predicate to a 1-arity function.

Normalize any collection to a list. Maps become [k, v] pairs.

Raise a type error for vector used where predicate/function expected.

Functions

graphemes(s)

Convert string to list of graphemes.

normalize_keyfn(key)

Normalize a key/function to a 1-arity value-extracting function.

Same as normalize_pred/2 with :value mode but with a different vector error message ("function or key" vs "predicate").

normalize_pred(key, arg2)

Normalize a predicate to a 1-arity function.

Mode :truthy returns a boolean-coercing function (for filter, remove, find, every?, not_any?, take_while, drop_while). Mode :value returns a value-extracting function (for some, keep).

to_seq(coll)

Normalize any collection to a list. Maps become [k, v] pairs.

vector_arg_error(v, type)

Raise a type error for vector used where predicate/function expected.