The HQL standard library provides 107+ functions for functional programming. ~96% are self-hosted in HQL (stdlib.hql); only true primitives (first, rest, cons, seq, range) are implemented in JavaScript.
All sequence operations are lazy by default — elements are computed on demand.
1. Sequence Primitives
These are the foundational functions implemented in JavaScript (core.js).
Function
Signature
Description
Lazy
first
(first coll)
First element. O(1) for arrays.
No
rest
(rest coll)
All elements after first. Returns empty seq (not nil).
Yes
cons
(cons item coll)
Prepend item to collection. Returns Cons cell.
No
seq
(seq coll)
Convert to lazy seq. Returns null if empty (nil-punning).
Yes
next
(next coll)
Like (seq (rest coll)). Returns null if no more elements.
Yes
2. Collection Operations
Function
Signature
Description
Lazy
take
(take n coll)
First n elements.
Yes
drop
(drop n coll)
Skip first n elements.
Yes
map
(map f coll)
Apply f to each element. Multi-collection: (map f c1 c2).
Yes
filter
(filter pred coll)
Keep elements where pred is truthy.
Yes
reduce
(reduce f init coll)
Reduce to single value. Supports early termination via (reduced val).
No
concat
(concat & colls)
Concatenate multiple collections. Stack-safe.
Yes
flatten
(flatten coll)
Recursively flatten nested collections.
Yes
distinct
(distinct coll)
Remove duplicates (uses Set).
Yes
count
(count coll)
Number of elements. O(1) for arrays/strings.
No
last
(last coll)
Last element. O(1) for arrays.
No
nth
(nth coll idx)
Element at index. Optional not-found value: (nth coll idx default).
No
second
(second coll)
Alias for (nth coll 1 nil).
No
reverse
(reverse coll)
Reverse a collection.
No
conj
(conj coll & items)
Add items to collection (end for vectors, front for seqs).
No
empty
(empty coll)
Return empty collection of same type.
No
vec
(vec coll)
Convert any collection to a concrete array.
No
set
(set coll)
Convert collection to a Set.
No
doall
(doall coll)
Force realization of entire lazy seq. Returns array.
No
3. Higher-Order Functions
Function
Signature
Description
Lazy
mapIndexed
(mapIndexed f coll)
Map with (index, item).
Yes
keepIndexed
(keepIndexed f coll)
Map-filter with indices, keeps non-nil results.
Yes
mapcat
(mapcat f coll)
Map then flatten one level.
Yes
keep
(keep f coll)
Map-filter: keeps non-nil results of f.
Yes
4. Conditional Lazy Operations
Function
Signature
Description
Lazy
takeWhile
(takeWhile pred coll)
Take while predicate is true.
Yes
dropWhile
(dropWhile pred coll)
Drop while predicate is true.
Yes
splitWith
(splitWith pred coll)
Returns [(takeWhile pred coll) (dropWhile pred coll)].
No
splitAt
(splitAt n coll)
Returns [(take n coll) (drop n coll)].
No
5. Reduction Variants
Function
Signature
Description
Lazy
reductions
(reductions f init coll)
Lazy seq of intermediate reduce values.
Yes
reduced
(reduced val)
Early termination marker for reduce.
No
6. Sequence Combinators
Function
Signature
Description
Lazy
interpose
(interpose sep coll)
Insert separator between elements.
Yes
interleave
(interleave & colls)
Interleave multiple sequences.
Yes
7. Partition Family
Function
Signature
Description
Lazy
partition
(partition n coll)
Partition into groups of n. Drops incomplete.
Yes
partition
(partition n step coll)
With explicit step size.
Yes
partitionAll
(partitionAll n coll)
Like partition but includes incomplete final group.
~96% of the standard library is implemented in HQL itself. Only true primitives that require direct JavaScript for performance or bootstrapping remain in JS: