Skip to content

Instantly share code, notes, and snippets.

View CTMacUser's full-sized avatar

Daryle Walker CTMacUser

View GitHub Profile
@CTMacUser
CTMacUser / NNNN-multipass-sequences.md
Created March 26, 2019 03:48
An improvement to the Swift library cancelled due to ABI stability.

Multiple-Pass Sequences and Cycle Detection

During the review process, add the following fields as needed:

@CTMacUser
CTMacUser / ForEachIndex.swift
Last active March 2, 2019 07:07
Extension to loop over each Collection Index without the retention issues indices has. Plus, example usage for MutableCollection, and an extra related method for RangeReplaceableCollection.
// ForEachIndex.swift by Daryle Walker
extension Collection {
/**
Calls the given closure on each element index in the collection in the
same order as a `for`-`in` loop.
The two loops in the following example produce the same output:
@CTMacUser
CTMacUser / RotateSwapMove.swift
Last active March 2, 2019 06:11
Extensions to MutableCollection to swap multiple elements at a time, plus support methods to rotate, and example methods to move elements.
// RotateSwapMove.swift by Daryle Walker
extension MutableCollection {
/**
Rotates the elements such that the value at the given index is now at `startIndex`.
Passing `startIndex` as `i` has no effect.
The method applies a left-rotation, bringing the target element's value to `startIndex`.
@CTMacUser
CTMacUser / BasicSetSubtraction.swift
Last active February 20, 2019 05:23
A sorted sequence with elements of another sorted sequence filtered out. Based on <https://forums.swift.org/t/how-to-effectively-filter-array-by-another-array-in-functional-paradigm/20442>.
// BasicSetSubtraction.swift by Daryle Walker
/// An iterator that vends elements from a sorted wrapped iterator, subtracting the elements from in another wrapped sorted filter iterator.
public struct SetSubtractionIterator<Base: IteratorProtocol, Filter: IteratorProtocol> where Base.Element == Filter.Element, Base.Element: Comparable {
/// The iterator where the vended elements come from.
var base: Base
/// The iterator where matches to be filtered come from.
var filters: Filter
@CTMacUser
CTMacUser / StridingSequence.swift
Created February 1, 2019 05:26
A sequence that strides over most of its wrapped sequence's elements.
//
// StridingSequence.swift
// CLITest
//
// Created by Daryle Walker on 1/31/19.
// Copyright © 2019 Daryle Walker. All rights reserved.
//
// WARNING: I think this requires Swift 5, since it needs Sequence to no longer have an SubSequence member.
@CTMacUser
CTMacUser / MultipleSearch.swift
Last active January 23, 2019 23:50
Searching for a subsequence within a sequence. Also, rotating elements and a ring-buffer collection.
/*
MultipleSearch.swift -- Sequence and collection multi-element search, all locations
Copyright (c) 2019 Daryle Walker
*/
// MARK: Searching for every occurance of a string of elements within a sequence
extension Sequence {
@CTMacUser
CTMacUser / LazyEmptyAdmittingSplitCollection.swift
Created December 22, 2018 00:52
Attempts to make a lazy version of the Collection.split function.
/**
A lazy wrapper for `Collection.split`, but only when empty subsequences can also be vended.
Based off the `LazySplitCollection` sample type in the [article "Conditional Conformance in the Standard Library" at the Swift Blog](https://swift.org/blog/conditional-conformance/) by [Ben Cohen](https://twitter.com/airspeedswift/), but extended only to support maximum subsequence counts.
*/
public struct LazyEmptyAdmittingSplitCollection<Base: Collection> {
/// The wrapped collection, whose subsequences will be vended as elements of `self`.
let base: Base
/// The maximum number of splits allowed; the count of subsequences vended is at most one greater than this.
@CTMacUser
CTMacUser / NNNN-diverges.md
Last active May 14, 2020 04:25
A proposal to generalize the Sequence comparison methods, with specializations for Collections.

Locating Sequence-Commonality Breaks

Introduction

@CTMacUser
CTMacUser / Int4.swift
Created June 23, 2018 22:34
Four-bit signed and unsigned integer types in Swift.
//
// Int4.swift
// NegaSuperBinary
//
// Created by Daryle Walker on 6/22/18.
// Copyright © 2018 Daryle Walker. All rights reserved.
//
import Foundation
@CTMacUser
CTMacUser / SegmentedArray.swift
Created April 18, 2018 08:39
An array with distributed storage, in Swift.
//
// SegmentedArray.swift
// NodeCollections
//
// Created by Daryle Walker on 4/15/18.
// Copyright © 2018 Daryle Walker. All rights reserved.
//
// MARK: Globals