Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class NonEmptyArray2<A> {
- constructor(readonly first: A, readonly second: A, readonly tail: ReadonlyArray<A>) {}
- toArray(): A[] {
- return [this.first, this.second, ...this.tail];
- }
- }
- class xD<A> {
- constructor(readonly first: A, readonly second: A, readonly tail: ReadonlyArray<A>) { }
- toArray(): A[] {
- return [this.first];
- }
- }
- function needToAccessTwoItemsFunction(youShouldBeHappy: NonEmptyArray2<number>): void {
- const array = youShouldBeHappy.toArray();
- console.log(array[0]);
- console.log(array[1]);
- }
- needToAccessTwoItemsFunction(new NonEmptyArray2<number>(1, 2, []));
- needToAccessTwoItemsFunction(new xD<number>(1, 2, []));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement