41 - Lens Example
by steen_hansen
HTML
<!DOCTYPE html><meta charset="utf-8" />
<title>41 Lens Example</title>
<div id='js-div' style="width:52%">
<a href='https://github.com/steenhansen/type-czech' target="_blank" class='git-hub'>GitHub Package</a>
<div id='js-code'>the javascript</div>
<br>
</div>
<div id="the-explanation" style="width:48%" >
<div class='an-explantion'>41 - Lens Example</div>
<div id='explanation-text'>
<br>
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.
<pre>
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} ...`
}
</pre>
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.
<br><br>
<!-- -----------------TYPE 1------------------------ -->
<script src="https://cdn.jsdelivr.net/gh/steenhansen/type-czech@latest/web-resources/consolelog.js"></script>
<script...