@@ -32,20 +32,20 @@ import Optional from 'typescript-optional';
3232### creating ` Optional<T> ` objects
3333
3434``` ts
35- let nullableString: string | null = /* some nullable value */ ;
35+ const nullableString: string | null = /* some nullable value */ ;
3636
3737// all the following variables will be parameterized as Optional<string>.
38- let optional = Optional .ofNullable (nullableString );
39- let optionalPresent1 = Optional .ofNullable (" foo" );
40- let optionalPresent2 = Optional .ofNonNull (" foo" ); // accepts non-null value (or else throws TypeError)
41- let optionalEmpty1: Optional <string > = Optional .empty (); // type hinting required
42- let optionalEmpty2 = Optional .empty <string >(); // or parameterize explicitly
38+ const optional = Optional .ofNullable (nullableString );
39+ const optionalPresent1 = Optional .ofNullable (" foo" );
40+ const optionalPresent2 = Optional .ofNonNull (" foo" ); // accepts non-null value (or else throws TypeError)
41+ const optionalEmpty1: Optional <string > = Optional .empty (); // type hinting required
42+ const optionalEmpty2 = Optional .empty <string >(); // or parameterize explicitly
4343```
4444
4545### operations
4646
4747``` ts
48- let optional: Optional <string > = Optional .ofNullable ( /* some optional value: null | string */ );
48+ const optional: Optional <string > = Optional .ofNullable ( /* some optional value: null | string */ );
4949
5050// force to retrieve the payload. (or else throws TypeError.)
5151// this method is not used match.
@@ -70,13 +70,13 @@ optional.filter(value => value.length > 0);
7070optional .map (value => value .length );
7171
7272// map a payload with the given mapper which returns value wrapped with Optional type.
73- let powerIfPositive: (x : Number ) => Optional <Number >
73+ const powerIfPositive: (x : Number ) => Optional <Number >
7474 = x => (x > 0 ) ? Optional .ofNonNull (x * x ) : Optional .empty ();
75- let numberOptional: Optional <number > = Optional .ofNullable (/* some optional value: null | number */ )
75+ const numberOptional: Optional <number > = Optional .ofNullable (/* some optional value: null | number */ )
7676numberOptional .flatMap (value => powerIfPositive (value ));
7777
7878// return this if this is present, return the given another optional otherwise.
79- let another: Optional <string > = Optional .ofNullable (/* ... */ );
79+ const another: Optional <string > = Optional .ofNullable (/* ... */ );
8080optional .or (another );
8181
8282// retrieve a payload if this is present, return the given value otherwise.
0 commit comments