Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds a comprehensive set of utility functions to the Koka standard library for both vectors and lists, enhancing functional programming capabilities.
Key Changes:
- Added vector operations including folding (
foldl,foldr), zipping (zip,zip-with,zip-with-indexed), and collection manipulation (take,drop,slice,reverse,append) - Introduced predicate/equality-based overloads for list functions using namespace prefixes (
pred/andeq/) - Added missing comparison operators for
ssize_ttype (==,!=,>)
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| lib/std/core/vector.kk | Adds functional programming utilities (fold, zip, map-indexed), collection manipulation functions (take, drop, slice, reverse, append), equality operators, and additional ssize_t comparison operators |
| lib/std/core/list.kk | Refactors existing functions with namespace prefixes (pred/, eq/) and adds equality-based variants (contains, eq/remove, eq/lookup, eq/index-of) with improved parameter destructuring |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| pub fun eq/index-of( xs : list<a>, value : a, ?(==) : (a,a) -> e bool ) : e maybe<int> | ||
| fun recur( ys, idx ) | ||
| match ys | ||
| Cons(y,yy) -> if y==value then Just(idx) else recur(yy,idx+1) | ||
| Nil -> Nothing |
There was a problem hiding this comment.
The return type is inconsistent with pred/index-of which returns int (with -1 for not found). This function returns maybe<int>, which creates an inconsistency in the API. Consider either returning int with -1 for consistency, or updating both functions to use maybe<int>.
| pub fun eq/index-of( xs : list<a>, value : a, ?(==) : (a,a) -> e bool ) : e maybe<int> | |
| fun recur( ys, idx ) | |
| match ys | |
| Cons(y,yy) -> if y==value then Just(idx) else recur(yy,idx+1) | |
| Nil -> Nothing | |
| pub fun eq/index-of( xs : list<a>, value : a, ?(==) : (a,a) -> e bool ) : e int | |
| fun recur( ys, idx ) | |
| match ys | |
| Cons(y,yy) -> if y==value then idx else recur(yy,idx+1) | |
| Nil -> -1 |
| unsafe-assign(w,i + l1,v2.unsafe-idx(i)) | ||
| w | ||
|
|
||
| // Append two vectors |
There was a problem hiding this comment.
The documentation comment "Append two vectors" is duplicated from the append function above (line 274). This should describe that it's an operator alias for append or reference the append function.
| // Append two vectors | |
| // Operator alias for `append`: append two vectors. |
237feda to
eb4d604
Compare
eb4d604 to
52881c8
Compare
No description provided.