Advertisement
Guest User

Untitled

a guest
Jul 13th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class NonEmptyArray2<A> {
  2.     constructor(readonly first: A, readonly second: A, readonly tail: ReadonlyArray<A>) {}
  3.  
  4.     toArray(): A[] {
  5.         return [this.first, this.second, ...this.tail];
  6.     }
  7. }
  8.  
  9. class xD<A> {
  10.     constructor(readonly first: A, readonly second: A, readonly tail: ReadonlyArray<A>) { }
  11.    
  12.     toArray(): A[] {
  13.         return [this.first];
  14.     }
  15. }
  16.  
  17. function needToAccessTwoItemsFunction(youShouldBeHappy: NonEmptyArray2<number>): void {
  18.     const array = youShouldBeHappy.toArray();
  19.     console.log(array[0]);
  20.     console.log(array[1]);
  21. }
  22.  
  23. needToAccessTwoItemsFunction(new NonEmptyArray2<number>(1, 2, []));
  24. needToAccessTwoItemsFunction(new xD<number>(1, 2, []));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement