Skip to content

Generalize Ranges to support characters and other comparable values #647

Open

Description

@avramlevitter

Many other languages support the concept of a range that can be any sequence that meets simple criteria, beyond just integer sequences. I was looking to use a shorthand to create a list of characters from 'a' to 'z' but ranges only supports Integers, which means I needed to do

Range.from_to_inclusive(Char"a".to_int(), Char"z".to_int()).to_list().map(Char.from_int)

This could also apply to other kinds of sequences, such as dates.

Activity

  1. jackfirth commented on Mar 28, 2025

    @jackfirth
    Collaborator

    Generalizing ranges is something we're interested in, but not focused on currently. There's some design questions to sort out, like whether ranges will be restricted to Comparable values or whether they'll accept any value and include a corresponding Comparator object.

  2. changed the title [-]Allow ranges for Char (and other types that support a generic increment and equality comparison)[/-] [+]Generalize Ranges to support characters and other comparable types[/+] on Mar 28, 2025
  3. changed the title [-]Generalize Ranges to support characters and other comparable types[/-] [+]Generalize Ranges to support characters and other comparable values[/+] on Mar 28, 2025
  4. added
    enhancementNew feature or request
    librariesThis is for issues related to Rhombus libraries
    on Mar 28, 2025
  5. usaoc commented on Mar 28, 2025

    @usaoc
    Collaborator

    start ..= end ranges also work as sequences, so I’d write

    for List (i in Char"a".to_int() ..= Char"z".to_int()):
      Char.from_int(i)
    

    This is still sub-optimal, admittedly. Ideally, (Char"a" ..= Char"z").to_list() should work just fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestlibrariesThis is for issues related to Rhombus libraries

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions