Customer details specificationλ︎
Create a new file for the specifications,
src/practicalli/banking_specifications.cljc, with the namespace
clojure.spec.alpha library with an alias of
Define basic customer detailsλ︎
Define a specification for the customer-details map, composed of all the required keys that define a customer.
The bank legally requires specific information about a customer in order to add them as an account holder
INFO::A more detailed email specificationλ︎
Use a regular expression to define the syntax of an email address, eg. firstname.lastname@example.org
A residential address is made from several pieces of information and is defined as a composite specification, from several specifications.
(spec/def ::house-name-number (spec/or :string string? :number int?)) (spec/def ::street-name string?) (spec/def ::post-code string?) (spec/def ::county string?) (spec/def ::country string?)
(spec/def ::residential-address (spec/keys :req [::house-name-number ::street-name ::post-code] :opt [::county ::country]))
A social security number specification is also a candidate for a composite specification. Social security numbers may take different forms and even have different names in different countries, eg. the USA SSN is a nine-digit number in the format "AAA-GG-SSSS"
In the UK the social security number is called the National Insurance number and is of the form QQ123456C
INFO::Detailed social security numbers would check the different formsλ︎
Predicate functions can be defined to check for the size of the different social security forms.
A general social security specification can now be defined, with one of any of the country specific specifications
Composing the customer details specificationλ︎
A customer details specification is a hash-map of key value pairs. The keys are the specifications that have just been defined.
spec/keys creates a specification for a hash-map with required and optional keys.
spec/keys also includes a check for a map, so no explicit check for a map is required.
(spec/def ::customer-details (spec/keys :req [::first-name ::last-name ::email-address ::residential-address ::social-security-id]))