Skip to content
/ Set Public
forked from robrix/Set

An implementation of Multiset and PredicateSet in Swift.

License

Notifications You must be signed in to change notification settings

m4tbat/Set

 
 

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

About

An implementation of Multiset and PredicateSet in Swift.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 96.1%
  • Ruby 3.0%
  • C 0.9%