Skip to content

Unannotated partial functions #46

@kanwren

Description

@kanwren

Some functions are partial where they do not need to be, or are partial without being annotated as such:

  • serde.toTOML: throws when input is not TOML-convertible (i.e. not an attrset); should probably return an optional instead
  • list.slice and nonempty.slice: throws on negative start position (for consistency with builtins.substring I believe). Note that a start position past the end of the list/string returns an empty list/string, which I think is bad behavior. The slicing and substring functions should have their edge cases reconsidered; do we want negative starting positions to fail, or do we want to "ignore" invalid indices (e.g. string.substring (-1) 2 "ab" == "a")? Here's a short list of ways to improve these functions:
    • Consider negative indices the same as indices past the end of the list/string, and ignore them, returning only elements in range. Negative indices should not throw
    • string.substring uses a length (-1) to indicate "to the end", while list.slice uses null. These should probably both be a nullable int
    • Rename string.substring to string.slice to make it clear that they share the same semantics
    • Group the two int arguments into an attrset, so it's clear which one is start and which one is length, which also makes it easier to omit the length without writing (-1) or null.
    • Add extra range functions that take start/end indices instead of start index and length, again in an attrset
  • list.insertAt and nonempty.insertAt throw on an index out of bounds; these should either be annotated as @partial or their semantics should be changed (e.g. to return the list unchanged if the index is out of bounds, which I don't think is as good option)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions