<commit_before>swift-specification-pattern
===========================

Specification pattern implemented in swift<commit_msg>Added example code to README<commit_after>swift-specification-pattern
===========================

The **Specification** design pattern implemented in swift.

> In computer programming, the specification pattern is a particular software design pattern, whereby business rules can be recombined by chaining the business rules together using boolean logic.

Source: [wikipedia](http://en.wikipedia.org/wiki/Specification_pattern)



Example of use
--------------

In the following example, we are retrieving invoices and sending them to a collection agency if

1. they are overdue,
2. notices have been sent, and
3. they are not already with the collection agency.

This example is meant to show the end result of how the logic is 'chained' together.

	let overDue = OverDueSpecification()
	let noticeSent = NoticeSentSpecification()
	let inCollection = InCollectionSpecification()
 
	// example of specification pattern logic chaining
	let sendToCollection = overDue.and(noticeSent).and(inCollection.not())
 
	let invoiceCollection = Service.invoices()
	for invoice in invoiceCollection {
	    if sendToCollection.isSatisfiedBy(invoice) {
	        invoice.sendToCollection()
	    }
	}
	


License
-------

Code is under the MIT license.

{'fraction_non_alphanumeric': 0.11160058737151249, 'fraction_numerical': 0.0022026431718061676, 'mean_word_length': 4.563265306122449, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2575304', 'n_tokens_mistral': 359, 'n_tokens_neox': 326, 'n_words': 135}