Built-in Methods
Built-in methods are invoked using dot syntax on values. They operate as lazy range adapters in functional chains.
Transformation and Filtering
Section titled “Transformation and Filtering”| Method | Description |
|---|---|
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"). |
sort | Native 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. |
first | Returns first element (unwrapped). Errors on empty list. Property. |
empty | Returns 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]String Methods
Section titled “String Methods”| Method | Description |
|---|---|
split(sep) | Splits by separator, returns list. |
replace(old, new) | Replaces all occurrences. |
length | String 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"Object Methods
Section titled “Object Methods”| Method | Description |
|---|---|
length | Number of keys. Property. |
keys() | Returns list of key names. |
Stream Orchestration
Section titled “Stream Orchestration”| Method | Description |
|---|---|
take(n) | Limits to first N elements. |
drop(n) | Skips first N elements. |
collect | Captures lazy stream into a static list. |
join(sep?) | Concatenates all elements into a single string. |
buffer(n) | Sets bounded buffer size (default 1024). |
JSON Processing
Section titled “JSON Processing”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.jsonjsonl 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]Output Methods
Section titled “Output Methods”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)File Output (write to)
Section titled “File Output (write to)”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).
Assertion Methods (.must)
Section titled “Assertion Methods (.must)”The .must property is available on any value and returns an assertion proxy:
| Method | Description |
|---|---|
.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.