import { none , Option , some } from 'fp-ts/lib/Option' ; import { getTupleRing , Ring } from 'fp-ts/lib/Ring' ; const safeOptionRing = { zero : none , one : some ( 1 ) , add : ( x , y ) => x . fold ( y , ( _x ) => y . fold ( x , ( _y ) => some ( _x + _y ) ) ) , sub : ( x , y ) => x . fold ( y , ( _x ) => y . fold ( x , ( _y ) => some ( _x - _y ) ) ) , mul : ( x , y ) => x . fold ( y , ( _x ) => y . fold ( x , ( _y ) => some ( _x * _y ) ) ) , } ; const strictOptionRing = { zero : none , one : some ( 1 ) , add : ( x , y ) => x . fold ( none , ( _x ) => y . fold ( none , ( _y ) => some ( _x + _y ) ) ) , sub : ( x , y ) => x . fold ( none , ( _x ) => y . fold ( none , ( _y ) => some ( _x - _y ) ) ) , mul : ( x , y ) => x . fold ( none , ( _x ) => y . fold ( none , ( _y ) => some ( _x * _y ) ) ) , } ; const a = some ( 42 ) ; const b = none ; const c = some ( 21 ) ; const R1 = getTupleRing ( safeOptionRing , safeOptionRing , safeOptionRing ) ; console . log ( R1 . add ( [ a , b , c ] , [ b , a , c ] ) ) ; console . log ( R1 . add ( [ a , b , c ] , R1 . one ) ) ; console . log ( R1 . sub ( [ a , b , c ] , R1 . zero ) ) ; console . log ( R1 . mul ( [ a , b , c ] , [ a , b , c ] ) ) ; const R2 = getTupleRing ( strictOptionRing , strictOptionRing , strictOptionRing ) ; console . log ( R2 . add ( [ a , b , c ] , [ b , a , c ] ) ) ; console . log ( R2 . add ( [ a , b , c ] , R2 . one ) ) ; console . log ( R2 . sub ( [ a , b , c ] , R2 . zero ) ) ; console . log ( R2 . mul ( [ a , b , c ] , [ a , b , c ] ) ) ; const R3 = getTupleRing ( strictOptionRing , safeOptionRing , strictOptionRing ) ; console . log ( R3 . add ( [ a , b , c ] , [ b , a , c ] ) ) ; console . log ( R3 . add ( [ a , b , c ] , R3 . one ) ) ; console . log ( R3 . sub ( [ a , b , c ] , R3 . zero ) ) ; console . log ( R3 . mul ( [ a , b , c ] , [ a , b , c ] ) ) ;