This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A lightweight approach to parsing text with combinators. | |
# put together in an afternoon for a project by acb, dedicated to the public domain | |
# Inspired by Haskell Parsec and the PointFree swift-parsing library | |
import re | |
# elementary parsing functions. | |
# These take an input string and return `(parsed_value, remainder)` if | |
# successful, or `None` if not. | |
# The functions below generate a parsing function when called. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// a simple Swift translation of the Haskell State monad | |
// taken from http://brandon.si/code/the-state-monad-a-tutorial-for-the-confused/ | |
struct State<S,A> { | |
let run: ((S)->(A,S)) | |
} | |
let fromSToAAndS = { (v: Int) -> (String, Int) in | |
if v%5 == 0 { return ("foo", v+1) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// AudioBufferExtensions.swift | |
// Plink | |
// | |
// Created by acb on 20/03/2019. | |
// Copyright © 2019 Kineticfactory. All rights reserved. | |
// | |
// Extensions for AudioBuffer and related classes | |
import CoreAudio |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Generating UIImages functionally in Swift | |
// By Andrew Bulhak http://dev.null.org/acb/ github:andrewcb | |
// Distributed under the Apache Licence | |
// | |
// For more information, see http://tech.null.org/item/201603210210_functionally_uiimage | |
/* -------------------------------------------------------------- | |
A UIImage extension providing the means of functionally generating images; the general form is: | |
let myImage = UIImage (width: w, height: h) { (x, y) in return pixelValue } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// prefix-trie.swift A generic prefix-matching trie in Swift | |
// By Andrew Bulhak http://dev.null.org/acb/ | |
/** The prefix trie has two types: the type of input element, C, and the type of final result for a successful prefix match, T. */ | |
enum Trie<C:Hashable,T> { | |
typealias IndexType = C | |
typealias ResultType = T | |
case Success(value:T) | |
case Node([C:Trie<C,T>]) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Basic (Scala-esque) Futures/Promises in Swift on Linux (first draft) | |
* Author: Andrew Bulhak (https://github.com/andrewcb/) | |
* Distributed under Creative Commons CC-BY-SA. Some rights reserved. | |
* | |
* Note: this code will not be performant until there's a proper | |
* libdispatch available. | |
*/ | |
import Foundation | |
import NSLinux |