Skip to content

Lazy split #59

Closed
Closed
@kylemacomber

Description

@kylemacomber

Recently we've been exploring at FilePath APIs for Swift System, including extension:

let path: FilePath = "/tmp/archive.tar.gz"
print(path.stem!)
print(path.extension!)
// Prints "archive.tar"
// Prints "gz"

For more complicated cases, a lazy version of the existing split algorithm could be a handy and efficient (no heap allocations!) way to operate on a path with multiple extensions:

let path: FilePath = "/tmp/archive.tar.gz"
for component in path.basename!.string.lazy.split(separator: ".") {
    print(component)
}
// Prints "archive"
// Prints "tar"
// Prints "gz"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions