Skip to content

Instantly share code, notes, and snippets.

@milseman
milseman / v2_filepath_syntactic_operations.md
Last active Feb 5, 2021
[Proposal v2] FilePath Syntactic Operations
View v2_filepath_syntactic_operations.md

FilePath Syntactic Operations

Introduction

FilePath appeared in System 0.0.1 with a minimal API. This proposal adds API for syntactic operations, which are performed on the structure of the path and thus do not consult with the file system or make any system calls. These include inspecting the structure of paths, modifying paths, and accessing individual components.

@milseman
milseman / filepath_syntactic_operations.md
Last active Jan 21, 2021
[Proposal] FilePath Syntactic Operations
View filepath_syntactic_operations.md

FilePath Syntactic Operations

Introduction

FilePath appeared in System 0.0.1 with a minimal API. This proposal adds API for syntactic operations, which are performed on the structure of the path and thus do not consult with the file system or make any system calls. These include inspecting the structure of paths, modifying paths, and accessing individual components.

Additionally, this proposal greatly expands Windows support and enables writing platform-agnostic path manipulation code.

Future Work: Operations that consult the file system, e.g. resolving symlinks.

@milseman
milseman / offset_bound_proposal.md
Last active Oct 6, 2019
Offset-Based Access to Indices, Elements, and Slices
View offset_bound_proposal.md

Changes in v2

  • Removed .start and .end, now all OffsetBounds are built from .first and .last.
    • Simplifies usage and learnability. .last + 1 representing the end is mostly only relevant to documentation.
    • Better delineates OffsetBound abstraction and terminology from indices.
  • Added RangeReplaceableCollection convenience overloads, as well as subscript setters.
    • .insert(at:), .remove(at:), etc.,
@milseman
milseman / string_formatters.swift
Last active Sep 11, 2019
String Formatters Through Interpolation
View string_formatters.swift
struct StringFormatters {
var text = "Hello, World!"
}
/*
This is the master template for fprintf format string functionality.
For development purposes only
```
@milseman
milseman / collection_searchers.swift
Last active Jul 6, 2019
WIP: Collection Consumers and Searchers
View collection_searchers.swift
///
/// Collection Consumers
///
protocol CollectionConsumer {
associatedtype Element
func consumeFront<C: Collection>(_ c: C) -> C.Index? where C.Element == Element
}
View offset_bound_gist.swift
// The below will be a customization point on Collection. For the purposes of
// this gist, we'll fake/approximate it with static overloads
extension Collection {
/// Returns an index `distance` positions prior to `i` if it exists.
///
/// Other methods such as `index(_:offetBy:)` must not be passed a negative
/// offset if the collection is bidirectional. This method will perform a
/// negative offset even if the collection is not bidirectional, by using a
/// less efficient means. `BidirectionalCollection` customizes this with a
@milseman
milseman / offset_no_range_no_label.swift
Last active May 6, 2019
Offset indexing, no range, no label
View offset_no_range_no_label.swift
// TODO: doc
public struct OffsetBound {
internal enum Kind {
case fromStart(Int)
case fromEnd(Int)
}
internal var kind: Kind
internal init(fromStart: Int) {
self.kind = .fromStart(fromStart)
@milseman
milseman / offset_no_range_explicit_end.swift
Created May 6, 2019
Offset Indexing, no range, explicit end
View offset_no_range_explicit_end.swift
// TODO: doc
public struct OffsetBound {
internal enum Kind {
case fromStart(Int)
case fromEnd(Int)
}
internal var kind: Kind
internal init(fromStart: Int) {
self.kind = .fromStart(fromStart)
@milseman
milseman / offset_no_range_phantom.swift
Created May 3, 2019
Broken: Offset Indexing, Existing ranges, Phantom typed
View offset_no_range_phantom.swift
// TODO: doc
public struct OffsetBound<Bound> {
internal enum Kind {
case fromStart(Int)
case fromEnd(Int)
}
internal var kind: Kind
public init(fromStart: Int) {
self.kind = .fromStart(fromStart)
@milseman
milseman / offset_indexing_no_range.swift
Created May 3, 2019
Offset Indexing, only OffsetBound
View offset_indexing_no_range.swift
// TODO: doc
public struct OffsetBound {
internal enum Kind {
case fromStart(Int)
case fromEnd(Int)
}
internal var kind: Kind
public init(fromStart: Int) {
self.kind = .fromStart(fromStart)