Skip to content

Instantly share code, notes, and snippets.

@ushpizin
ushpizin / Permutations.swift
Last active September 8, 2017 08:36 — forked from proxpero/Permutations.swift
Generate the permutations of a Swift array.
//: Permutations
// based on https://www.objc.io/blog/2014/12/08/functional-snippet-10-permutations/
// but updated for Swift 3.0 (Xcode 8.3)
extension Array {
func decompose() -> (Generator.Element, [Generator.Element])? {
guard let x = first else { return nil }
return (x, Array(self[1..<count]))
}
}
@ushpizin
ushpizin / DateComponents+Comparable.swift
Created December 27, 2016 11:39
Comparable extension of DateComponents
//
// DateComponents+Comparable.swift
//
// Created by Liran on 27/12/2016.
// License: MIT
//
import Foundation
extension DateComponents: Comparable {