millsp / medium

📰 Developer versions of my Medium.com articles
GNU Affero General Public License v3.0
126 stars 16 forks source link

Simpler Last type #3

Closed ackvf closed 4 years ago

ackvf commented 4 years ago

I took your Tail function and created a simpler Last implementation. https://github.com/pirix-gh/medium/blob/294725cd723b1a66cfb8b441c862a0d2d5bd184d/types-curry-ramda/src/index.ts#L177-L180

type Last<T extends any[]> = 
  ((...t: T) => any) extends ((_: any, ...rest: infer TT) => any)
    ? T[TT['length']]
    : never

type T1 = [10, 20, 30]
type T3 = Last<T1> // 30

https://github.com/pirix-gh/medium/blob/294725cd723b1a66cfb8b441c862a0d2d5bd184d/types-curry-ramda/src/index.ts#L408-L415

Thanks bunch for the article, I index in it quite often.

millsp commented 4 years ago

Hi thanks @ackvf, I took your advice long time ago and integrated the changes here.

So I'll just keep this article as is (since it's for learning purposes mostly).

Cheers,