Skip to content
This repository has been archived by the owner on May 19, 2018. It is now read-only.
/ Set Public archive

An implementation of Multiset and PredicateSet in Swift.

License

Notifications You must be signed in to change notification settings

robrix/Set

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Set

Build status

This is a Swift microframework which implements a PredicateSet and a Dictionary-backed Multiset.

Use

Multiset:

// Union
Multiset(1, 2, 3) + Multiset(3, 4, 5) // == Multiset(1, 2, 3, 3, 4, 5)

// Difference
Multiset(1, 2, 3) - Multiset(2, 3) // == Multiset(1)

// Intersection
Multiset(1, 2, 3) & Multiset(3, 4, 5) // == Multiset(3)

PredicateSet:

// Union
let union = PredicateSet { $0 > 0 } + PredicateSet { $0 % 2 == 0 }
union.contains(3) // true

// Difference
let difference = PredicateSet { $0 > 0 } - PredicateSet { $0 % 2 == 0 }
difference.contains(6) // false

// Special Sets
func isInt(number: Float) -> Bool {
	return Float(Int(number)) == number
}

let Q: PredicateSet<Float> = PredicateSet { _ in true } // Set of all real numbers.
let Z = Q & PredicateSet { isInt($0) } // Set of all integers.
let N = Z & PredicateSet { $0 > 0 } // Set of all natural numbers.

N.contains(1) // true
N.contains(-1.5) // false

See Multiset.swift and PredicateSet.swift for more details.

Integration

  1. Add this repo as a submodule in e.g. External/Set:

     git submodule add https://github.com/robrix/Set.git External/Set
    
  2. Drag Set.xcodeproj into your .xcworkspace/.xcodeproj.

  3. Add Set.framework to your target’s Link Binary With Libraries build phase.

  4. You may also want to add a Copy Files phase which copies Set.framework (and any other framework dependencies you need) into your bundle’s Frameworks directory. If your target is a framework, you may instead want the client app to include Set.framework.

Thanks