GitHub Package
the javascript

41 - Lens Example

A contrived lens example using Ramda. The lenses have to be injected into the functions to highlight their use. In a real program the lenses would be constants, not parameters, and be used like below.
function PRE_check_getAddress(an_address){ 
  the_first = R.view(SUB_LENSES.first_lens, an_address)
  the_last  = R.view(SUB_LENSES.last_lens, an_address)
  the_state = R.view(SUB_LENSES.state_lens, an_address)
  the_city  = R.view(SUB_LENSES.city_lens, an_address)
  the_zip   = R.view(SUB_LENSES.zip_lens, an_address)
  the_addr = {the_first, the_last, the_state, the_city, the_zip}
  type_err = type_czech.checkParam_type(the_addr, ADDR_SHAPE)
  type_czech.check_assert(type_err, 'ERROR - Lenses', the_addr)
}

function getAddress(an_address){
  the_first = R.view(SUB_LENSES.first_lens, an_address)
  the_last  = R.view(SUB_LENSES.last_lens, an_address)
  the_state = R.view(SUB_LENSES.state_lens, an_address)
  the_city  = R.view(SUB_LENSES.city_lens, an_address)
  the_zip   = R.view(SUB_LENSES.zip_lens, an_address)
  return `${the_first} ${the_last}, ${the_city}, ${the_state} ...`
}
Note use of check_assert() with the results of checkParam_type(); no return statement needed. The error that is found is the British postal code not being the same shape as the US zipcode.

Console Output