<commit_before>---
title: "Predefined functions"
---

Unless otherwise stated, all predefined functions throw an error if called with
the wrong number of parameters.

## map

`map(xs, f)` is equivalent to:

    fn(f, xs) xs.map(fn(x, _i, _a) f(x))

## join

`join(xs, separator)` is equivalent to:

    xs.join(separator)

## foldLeft

`foldLeft(xs, f, z)` is equivalent to:

    xs.reduce(f, z)

## fold

`fold` is equivalent to `foldLeft`.

## reduce

`reduce(xs, f)` is equivalent to:

    xs.reduce(f)

## foldRight

`foldRight(xs, f, z)` is equivalent to:

    reverse(xs).reduce(flip(f), z)

## reverse

`reverse(xs)` returns an array like `xs` but with its elements in reverse order.

## isEmpty

`isEmpty(xs)` is equivalent to:

    xs.length = 0

## head

`head(xs)` is equivalent to:

    xs[0]

## tail

`tail(xs)` is equivalent to:

    xs.slice(1)

## toArray

`toArray(xs)` is equivalent to:

    [].slice.call(xs)

## flip

`flip(f)` is equivalent to:

    fn(a, b) f(b, a)

## get

`get(obj, k)` is equivalent to:

    obj[k]

## set

`set(obj, k, v)` is equivalent to:

    obj[k] = v<commit_msg>Fixes #11 removes library functions stuff<commit_after>---
title: "Utility functions"
---

There are plans to eventually include a library of utility functions to use with
Squiggle, in the spirit of [lodash][].

[lodash]: https://lodash.com/
{'fraction_non_alphanumeric': 0.15140324963072377, 'fraction_numerical': 0.003692762186115214, 'mean_word_length': 3.4719471947194718, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6789680', 'n_tokens_mistral': 530, 'n_tokens_neox': 497, 'n_words': 165}