All Projects → ksxnodemodules → Typescript Tuple

ksxnodemodules / Typescript Tuple

Licence: mit
Generics to work with tuples in TypeScript

Programming Languages

typescript
32286 projects

Labels

Projects that are alternatives of or similar to Typescript Tuple

Mlib
Library of generic and type safe containers in pure C language (C99 or C11) for a wide collection of container (comparable to the C++ STL).
Stars: ✭ 321 (+172.03%)
Mutual labels:  generic
Processmemoryutilities.net
Implements performant ReadProcessMemory and WriteProcessMemory with generic type parameters using InlineIL
Stars: ✭ 42 (-64.41%)
Mutual labels:  generic
Nytl
Modern C++ generic header-only template library.
Stars: ✭ 87 (-26.27%)
Mutual labels:  generic
Ecst
[WIP] Experimental C++14 multithreaded compile-time entity-component-system library.
Stars: ✭ 418 (+254.24%)
Mutual labels:  generic
Frunk
Funktional generic type-level programming in Rust: HList, Coproduct, Generic, LabelledGeneric, Validated, Monoid and friends.
Stars: ✭ 725 (+514.41%)
Mutual labels:  generic
Jsonapi
Swift Codable JSON:API framework
Stars: ✭ 53 (-55.08%)
Mutual labels:  generic
Coala Bears
Bears for coala
Stars: ✭ 276 (+133.9%)
Mutual labels:  generic
Scroll
Scroll - making scrolling through buffers fun since 2016
Stars: ✭ 100 (-15.25%)
Mutual labels:  generic
Servicestack.java
ServiceStack Java Libraries and Apps
Stars: ✭ 10 (-91.53%)
Mutual labels:  generic
Binary
Generic and fast binary serializer for Go
Stars: ✭ 86 (-27.12%)
Mutual labels:  generic
Soapengine
This generic SOAP client allows you to access web services using a your iOS app, Mac OS X app and AppleTV app.
Stars: ✭ 468 (+296.61%)
Mutual labels:  generic
Tablekit
Type-safe declarative table views.
Stars: ✭ 567 (+380.51%)
Mutual labels:  generic
Phpcollections
A set of collections for PHP.
Stars: ✭ 53 (-55.08%)
Mutual labels:  generic
Observable
The easiest way to observe values in Swift.
Stars: ✭ 346 (+193.22%)
Mutual labels:  generic
Goreuse
Generic Code for Go
Stars: ✭ 93 (-21.19%)
Mutual labels:  generic
Klib
A standalone and lightweight C library
Stars: ✭ 3,442 (+2816.95%)
Mutual labels:  generic
Libgenerics
libgenerics is a minimalistic and generic library for C basic data structures.
Stars: ✭ 42 (-64.41%)
Mutual labels:  generic
Web Client
Generic Linked Data browser and UX component framework. Apache license.
Stars: ✭ 105 (-11.02%)
Mutual labels:  generic
Generic Auto Updater
Generic Auto-Updater: a robust, user-friendly, clean and efficient Auto-Updater to maintain any client patched.
Stars: ✭ 95 (-19.49%)
Mutual labels:  generic
Forge
A Generic Low-Code Framework Built on a Config-Driven Tree Walker
Stars: ✭ 70 (-40.68%)
Mutual labels:  generic

TypeScript Tuple

Generics to work with tuples in TypeScript

Requirements

  • TypeScript ≥ 4.1.0

Usage

IsFinite

import { IsFinite } from 'typescript-tuple'

type Foo = IsFinite<[0, 1, 2]> // Expect: true
const foo: Foo = true

type Bar = IsFinite<[0, 1, 2, ...number[]]> // Expect: false
const bar: Bar = false

type Baz = IsFinite<[0, 1, 2], 'finite', 'infinite'> // Expect: 'finite'
const baz: Baz = 'finite'

First

import { First } from 'typescript-tuple'
type Foo = First<['a', 'b', 'c']> // Expect: 'a'
const foo: Foo = 'a'

Last

import { Last } from 'typescript-tuple'
type Foo = Last<['a', 'b', 'c']> // Expect: 'c'
const foo: Foo = 'c'

Tail

import { Tail } from 'typescript-tuple'
type Foo = Tail<['a', 'b', 'c']> // Expect: ['b', 'c']
const foo: Foo = ['b', 'c']

Append

import { Append } from 'typescript-tuple'
type Foo = Append<['a', 'b', 'c'], 'x'> // Expect: ['a', 'b', 'c', 'x']
const foo: Foo = ['a', 'b', 'c', 'x']

Prepend

import { Prepend } from 'typescript-tuple'
type Foo = Prepend<['a', 'b', 'c'], 'x'> // Expect: ['x', 'a', 'b', 'c']
const foo: Foo = ['x', 'a', 'b', 'c']

Reverse

import { Reverse } from 'typescript-tuple'
type Foo = Reverse<['a', 'b', 'c']> // Expect: ['c', 'b', 'a']
const foo: Foo = ['c', 'b', 'a']

Concat

import { Concat } from 'typescript-tuple'
type Foo = Concat<['a', 'b', 'c'], [0, 1, 2]> // Expect ['a', 'b', 'c', 0, 1, 2]
const foo: Foo = ['a', 'b', 'c', 0, 1, 2]

Repeat

import { Repeat } from 'typescript-tuple'

// Basic
type Foo = Repeat<'x', 5> // Expect ['x', 'x', 'x', 'x', 'x']
const foo: Foo = ['x', 'x', 'x', 'x', 'x']

// Using union
type Bar = Repeat<'x', 1 | 3 | 4> // Expect ['x'] | ['x', 'x', 'x'] | ['x', 'x', 'x', 'x']
const bar1: Bar = ['x']
const bar3: Bar = ['x', 'x', 'x']
const bar4: Bar = ['x', 'x', 'x', 'x']

// Using ambiguous 'number' type
type Baz = Repeat<'x', number> // Expect 'x'[]
const baz: Baz = Array<number>()

NOTES:

  • Due to TypeScript design limitations, using floating point numbers and negative numbers might lead to infinite loop within TSC compiler, avoid doing this.

ConcatMultiple

import { ConcatMultiple } from 'typescript-tuple'
type Foo = ConcatMultiple<[[], ['a'], ['b', 'c']]> // Expect ['a', 'b', 'c']
const foo: Foo = ['a', 'b', 'c']

Drop

import { Drop } from 'typescript-tuple'

type Foo = Drop<[0, 1, 2, 3, 4], 2> // Expect [2, 3, 4]
const foo: Foo = [2, 3, 4]

type Bar = Drop<[0, 1, 2, 3, 4, ...number[]], 2> // Expect [2, 3, 4, ...number[]]
const bar: Bar = [2, 3, 4]

type Baz = Drop<[0, 1, 2, 3, 4], 10> // Expect []
const baz: Baz = [2, 3, 4]

type Qux = Drop<[0, 1, 2, 3, 4, ...number[]], 10> // Expect number[]
const qux: Qux = [2, 3, 4]

SliceStartQuantity

import { SliceStartQuantity } from 'typescript-tuple'
type Foo = SliceStartQuantity<[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 2, 4> // Expect [2, 3, 4, 5]
const foo: Foo = [2, 3, 4, 5]

FillTuple

import { FillTuple } from 'typescript-tuple'
type Foo = FillTuple<[0, 1, 2, 3], 'r'>
const foo: Foo = ['r', 'r', 'r', 'r']

CompareLength

import { CompareLength } from 'typescript-tuple'

type Foo = CompareLength<[0, 1, 2], ['a', 'b', 'c']> // Expect: 'equal'
const foo: Foo = 'equal'

type Bar = CompareLength<[0, 1], ['a', 'b', 'c', 'd']> // Expect: 'shorterLeft'
const bar: Bar = 'shorterLeft'

type Baz = CompareLength<[0, 1, 2, 3], ['a', 'b']> // Expect: 'shorterRight'
const baz: Baz = 'shorterRight'

SortTwoTuple

import { SortTwoTuple } from 'typescript-tuple'

type Foo = SortTwoTuple<[0, 1], ['a', 'b', 'c', 'd']> // Expect: [[0, 1], ['a', 'b', 'c', 'd']]
const foo: Foo = [[0, 1], ['a', 'b', 'c', 'd']]

type Bar = SortTwoTuple<[0, 1, 2, 3], ['a', 'b']> // Expect: [['a', 'b'], [0, 1, 2, 3]]
const bar: Bar = [['a', 'b'], [0, 1, 2, 3]]

type Baz = SortTwoTuple<[0, 1, 2], ['a', 'b', 'c', 'd']> // Expect: [[0, 1, 2], ['a', 'b', 'c']]
const baz: Baz = [[0, 1], 3, ['a', 'b', 'c']]

type Qux = SortTwoTuple<[0, 1, 2], ['a', 'b', 'c', 'd'], 'EQUAL'> // Expect: 'EQUAL'
const qux: Qux = 'EQUAL'

ShortestTuple

import { ShortestTuple } from 'typescript-tuple'

type Foo = ShortestTuple<[[0, 1, 2], [false, true], ['a', 'b', 'c', 'd']]> // Expect: [false, true]
const foo: Foo = [false, true]

type Bar = ShortestTuple<[[0, 1, 2], ['a', 'b', 'c'], ...[false, true][]]> // Expect: [false, true]
const bar: Bar = [false, true]

LongestTuple

import { LongestTuple } from 'typescript-tuple'

type Foo = LongestTuple<[[0, 1, 2, 3], [false, true], ['a']]> // Expect: [0, 1, 2, 3]
const foo: Foo = [0, 1, 2, 3]

type Bar = LongestTuple<[[], [false, true], ...[0, 1, 2][]]> // Expect: [0, 1, 2]
const bar: Bar = [0, 1, 2]

FilterTuple

import { FilterTuple } from 'typescript-tuple'

type Foo = FilterTuple<[1, '1'], number> // Expect: [1]
const foo: Foo = [1]

type Bar = FilterTuple<[1, '1', null, true], 1 | '1' | true> // Expect: [1, '1', true]
const bar: Bar = [1, '1', true]

License

MIT @ Hoàng Văn Khải

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].