ts-pair
v1.1.1
Published
Pair class for TypeScript and JavaScript
Downloads
1
Readme
ts-pair
Pair classes for TypeScript and JavaScript
Install
npm install ts-pair --save
Example
let pair = new Pair( 1, "Hello" );
console.log( pair.first, ', ', pair.second ); // 1, Hello
console.log( 'Pair is ' + pair ); // Pair is [ 1, Hello ]
pair.first = 2;
pair.second = "hi";
console.log( 'JSON', pair.toJSON() ); // Pair is { "first": 2, "second": "hi" }
let [ first, second ] = pair.toArray();
console.log( first, second ); // 2, hi
// chainable
console.log( pair.setFirst( 10 ).setSecond( "bye" ).toString() ); // [ 10, bye ]
let otherPair = new Pair( 20, "bye" );
console.log( otherPair.equals( pair ) ? 'equal': 'different' ); // different
let aImmutable = new ImmutablePair( 20, "bye" );
console.log( aImmutable.equals( otherPair ) ? 'equal': 'different' ); // equal
aImmutable.first = "baz"; // Error
Available Types
IPair
interface, withgetFirst()
,getSecond()
,equals()
,toArray()
, andtoJSON()
AbstractPair
that implementsIPair
and declarestoString()
Pair
that extendsAbstractPair
ImmutablePair
that extendsAbstractPair