Skip to content

Built-in Methods

Built-in methods are invoked using dot syntax on values. They operate as lazy range adapters in functional chains.

MethodDescription
map(fn)Projects each element to a new value. Supports explicit and implicit lambdas.
filter(fn | pattern)Retains elements matching a predicate, glob pattern, or implicit lambda. Glob: filter("*.d").
sortNative string-based sort.
grep(pattern)Internal regex-powered filter (no process spawn).
each(fn)Like map but returns the original list. For side effects.
reduce(init, fn)Aggregates into a single value.
unique()Removes duplicates, preserving first occurrence order.
reverse()Reverses element order.
flatten()Flattens one level of nested lists.
sum()Sums numeric elements. Returns int if all ints, float if any float.
wordcount()Counts word frequencies. Returns [{word, count}] sorted by count desc.
firstReturns first element (unwrapped). Errors on empty list. Property.
emptyReturns true if the list has no elements. Property.
[1, 2, 3].map(a * 2) # [2, 4, 6]
[1, 2, 3, 4].filter(a > 2) # [3, 4]
[1, 2, 3].reduce(0, (acc, x) => acc + x) # 6
[[1, 2], [3]].flatten() # [1, 2, 3]
MethodDescription
split(sep)Splits by separator, returns list.
replace(old, new)Replaces all occurrences.
lengthString length. Property.
toUpper()Converts to uppercase.
toLower()Converts to lowercase.
trim()Removes leading/trailing whitespace.
contains(sub)Returns true if string contains substring.
startsWith(prefix)Returns true if string starts with prefix.
endsWith(suffix)Returns true if string ends with suffix.
toNumber()Converts to int or float. Also works on lists (maps each element).
extract(pattern)Pattern matching: # matches letters/digits, * matches any chars. Returns list of matches.
"a:b:c".split(":") # ["a", "b", "c"]
"hello world".replace("world", "lash") # "hello lash"
" padded ".trim() # "padded"
MethodDescription
lengthNumber of keys. Property.
keys()Returns list of key names.
MethodDescription
take(n)Limits to first N elements.
drop(n)Skips first N elements.
collectCaptures lazy stream into a static list.
join(sep?)Concatenates all elements into a single string.
buffer(n)Sets bounded buffer size (default 1024).

json promotes each stream element from string to parsed JSON object. If a line is not valid JSON, the chain fails with a method error.

For multi-line JSON documents, use join first:

`cat data.json`.join.json

jsonl is a lenient variant that skips invalid JSON lines instead of failing.

Property access uses bracket syntax:

`cat data.json`.join.json["items"][0]["name"]
`cat config.json`.join.json["database"]["host"]

Bracket access works with variables:

let key = "name"
`cat users.ndjson`.json[key]

write and writeln are methods available on any value:

  • .write(sink?) — Writes without a newline. On lists, concatenates.
  • .writeln(sink?) — Writes followed by a newline. On lists, writes each element on its own line.

Default sink is stdout. stdout and stderr are global output range sinks.

"Fetching...".writeln(stderr)
[1, 2, 3].writeln(stdout)

Block-scoped file writing:

write to "output.txt" as f {
"hello world".writeln(f)
[1, 2, 3].writeln(f)
}

The file is automatically closed when the block exits. Opened in write mode (truncates existing content).

The .must property is available on any value and returns an assertion proxy:

MethodDescription
.equal(expected)Value equality (string comparison).
.notEqual(expected)Value inequality.
.beGreaterThan(expected)Numeric greater-than.
.beLessThan(expected)Numeric less-than.
.contain(value)String/list contains.
.startWith(value)String starts with.
.endWith(value)String ends with.

.because("reason") overrides the default failure message.

In unittest blocks, a failed assertion stops the current test. In production code, a failed .must produces a LashError and stops execution.