Slacker News Slacker News logo featuring a lazy sloth with a folded newspaper hat
  • top
  • new
  • show
  • ask
  • jobs
Library
← Back to context

Comment by s_severus

6 years ago

A possibly more elegant TypeScript solution:

  type NonEmpty<T> = [T, ...T[]];
  
  function head<T>(input: NonEmpty<T>): T {
    return input[0];
  }

https://www.typescriptlang.org/play/?ssl=5&ssc=2&pln=1&pc=1#...

0 comments

s_severus

Reply

No comments yet

Contribute on Hacker News ↗

Slacker News

Product

  • API Reference
  • Hacker News RSS
  • Source on GitHub

Community

  • Support Ukraine
  • Equal Justice Initiative
  • GiveWell Charities