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 small set of utilities for working with Unicode and ASCII scalars. Here is what it does: | |
// | |
// 1. Make `UnicodeScalar` strideable. This enables ranges of Unicode Scalars such as "a"..."z". | |
// 2. Add strideable Unicode.ASCII.Scalar (type alias `ASCII`) to enable type-safe manipulation of ASCII bytes. | |
// 3. Define limited `+`/`-` operators for stridable types to make something like `"x" + ("A"-"a")` possible. | |
// 1. Make `UnicodeScalar` strideable. This enables ranges of Unicode Scalars such as "a"..."z". | |
// Constants used in `Strideable` conformance extension of `Unicode.Scalar` |
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
//: Playground - noun: a place where people can play | |
/// A protocol to provide an abstraction of types that hold a weak reference to a target object. | |
/// | |
/// It is defined because a single generic implementation cannot support existentials, as they | |
/// do not conform to themselves or `AnyObject`. Most of its API is defined by protocol extensions | |
/// to makes it easier to create existential wrapper `struct`s or `final class`es. | |
/// | |
/// Here is an example protocol and the corresponding weak reference |
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
// An operator for tuple splat of simple function arguments (up to six arguments implemented). | |
// by Hooman Mehr ([email protected]) | |
// Source released as public domain. | |
precedencegroup TupleSplatPrecedence { | |
associativity: left | |
higherThan: BitwiseShiftPrecedence | |
} | |
// Infix operator for on the fly tuple splat: |
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
// | |
// HTMLBuilder.swift | |
// | |
// This is a prototype code of a DSL to make it easier to generate HTML within Swift source code. | |
// | |
// This version of the prototype usues global constants for html elements because of a compiler limitation / bug. | |
// The intended behavior was having these globals static properties of `Html` type. | |
// | |
// Created by Hooman Mehr on 04/07/17. | |
// Copyright © 2017 Hooman Mehr. See the MIT license at the bottom. |
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
import Darwin | |
public protocol MutexValue { | |
mutating func lock() | |
mutating func locked() -> Bool | |
mutating func unlock() | |
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
// RationalNumber.swift | |
// | |
// A basic implementation of Rational numbers in Swift 3.0. | |
// (c) 2016 Hooman Mehr. Licensed under Apache License v2.0 with Runtime Library Exception | |
/// A data type to model rational numbers in Swift. | |
/// | |
/// It always uses fully-reduced representation for simplicity and clarity of comparisons and uses LCM |
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
// | |
// CollectionIndexExtensions.swift | |
// Swift3 | |
// | |
// Created by Hooman Mehr on 5/9/16. | |
// Copyright © 2016 Hooman Mehr. See the MIT license at the bottom. | |
// | |
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
// | |
// KeyValueStore.swift | |
// FoundationNG | |
// | |
// Created by Hooman Mehr on 4/27/16. | |
// Copyright © 2016 Hooman Mehr. See the MIT license at the bottom. | |
// | |
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
// | |
// API.swift | |
// | |
// Created by Taro Minowa on 6/10/14. | |
// Copyright (c) 2014 Higepon Taro Minowa. All rights reserved. | |
// | |
import Foundation | |
typealias JSONDictionary = Dictionary<String, AnyObject> |
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
// Recursive: | |
func factorial(num: Int) -> Int { | |
return num < 2 ? 1 : num * factorial(num - 1) | |
} | |
// Iterative: | |
func factorial2(num: Int) -> Int { |
NewerOlder