9.2.0 • Published 3 years ago

typescript-core v9.2.0

Weekly downloads
171
License
Apache-2.0
Repository
-
Last release
3 years ago

TS-Core

npm version

TS-Core is a library that provides replacement types for some basic structures of TypeScript, like undefined, null or Array<T>. It also provides a pattern-matching system capable to pseudo-emulate a simple algebraic data type system.

This project was originally inspired by the Rust programming language. If you are familiar this Rust, you should be able to use functional types very quickly.

Concept of matchables

A matchable is a value that can has a specific state among a list of possible states. For instance, futures which allow to deal with promises are matchables that have at a T instant one state between pending, fulfilled or failed. A state can either be valueless (only a name) like pending, or carry a value, like fulfilled which carries the success value and failed which carries the error value.

Matchables are dealt with using the pattern-matching match function:

import { Option, Some, match } from "typescript-core"

const message = Some("Hello world!")

// Match the future's state
match(message, {
    Some: (message) => println("Message: {}", message),
    None: () => println("No message to display :(")
})

Matching is exhaustive, meaning that if you omit to match any of the matchable's state, you will get an error:

// ERROR: Pattern 'None' is not covered
match(future, {
    Some: (message) => println("Message: {}", message)
})

Most code editors will also feature code completion, meaning that if you ask your editor to autocomplete the results in the matching object, you should see the list of all possible states for a given matchable.

Note that you can also match objects using the postfix method:

message.match({
    Some: (message) => println("Message: {}", message),
    None: () => println("No message to display :(")
})

The point of pattern-matching is to deal with all cases at once, as well as to prevent forgetting one of the states - you must deal with all them. If you only want to take a look at one specific state for instance, the matchable's class should provide you additional methods fulfilling this purpose.

Examples

You can also take a look at the examples.

Documentation

The documentation can be found in the docs folder.

Types documentation can be got by running yarn docs. HTML files will be put in the docs/types folder.

License

This project is released under the terms of license Apache 2.0.

9.2.0

3 years ago

9.1.2

3 years ago

9.1.1

3 years ago

9.1.0

3 years ago

9.0.1

3 years ago

9.0.0

3 years ago

8.6.1

3 years ago

8.6.0

3 years ago

8.4.8

3 years ago

8.5.0

3 years ago

8.4.7

3 years ago

8.4.6

3 years ago

8.4.5

3 years ago

8.4.4

3 years ago

8.4.1

3 years ago

8.4.3

3 years ago

8.4.2

3 years ago

8.4.0

3 years ago

8.2.0

3 years ago

8.3.0

3 years ago

8.1.6

4 years ago

8.1.5

4 years ago

8.1.4

4 years ago

8.1.3

4 years ago

8.1.2

4 years ago

8.1.0

4 years ago

8.1.1

4 years ago

8.0.10

4 years ago

8.0.6

4 years ago

8.0.4

4 years ago

8.0.3

4 years ago

8.0.0

4 years ago

7.8.2

4 years ago

7.8.1

4 years ago

7.7.1

4 years ago

7.7.0

4 years ago

7.6.2

4 years ago

7.6.1

4 years ago

7.6.0

4 years ago

7.5.9

4 years ago

7.5.5

4 years ago

7.5.8

4 years ago

7.5.4

4 years ago

7.4.3

4 years ago

7.4.2

4 years ago

7.5.3

4 years ago

7.5.2

4 years ago

7.5.1

4 years ago

7.4.1

4 years ago

7.4.0

4 years ago

7.3.6

4 years ago

7.3.5

4 years ago

7.3.4

4 years ago

7.3.2

4 years ago

7.3.1

4 years ago

7.3.0

4 years ago

7.0.0

4 years ago

7.1.0

4 years ago

7.2.1

4 years ago

7.2.0

4 years ago

6.9.6

4 years ago

6.9.5

4 years ago

6.9.4

4 years ago

6.9.2

4 years ago

6.9.1

4 years ago

6.9.3

4 years ago

6.9.0

4 years ago

6.8.7

4 years ago

6.8.8

4 years ago

6.8.6

4 years ago

6.8.5

4 years ago

6.8.1

4 years ago

6.8.2

4 years ago

6.8.4

4 years ago

6.8.0

4 years ago

6.7.1

4 years ago

6.7.0

4 years ago

6.6.0

4 years ago

6.5.3

4 years ago

6.4.4

4 years ago

6.4.3

4 years ago

6.4.2

4 years ago

6.3.3

4 years ago

6.4.1

4 years ago

6.4.0

4 years ago

6.3.2

4 years ago

6.3.0

4 years ago

6.3.1

4 years ago

6.1.1

4 years ago

6.2.0

4 years ago

6.1.0

4 years ago

6.0.6

4 years ago

6.0.5

4 years ago

6.0.4

4 years ago

5.8.0

4 years ago

6.0.3

4 years ago

5.7.0

4 years ago

5.6.4

4 years ago

5.6.3

4 years ago

5.6.2

4 years ago

5.4.4

4 years ago

5.4.1

4 years ago

5.4.0

4 years ago

5.3.0

4 years ago

5.2.1

4 years ago

5.1.0

4 years ago

5.2.0

4 years ago

5.0.0

4 years ago

3.0.0

4 years ago

2.6.7

4 years ago

2.6.6

4 years ago

2.6.9

4 years ago

2.6.8

4 years ago

2.6.5

4 years ago

2.6.3

4 years ago

2.6.4

4 years ago

2.6.2

4 years ago

2.6.0

4 years ago

2.4.1

4 years ago

2.4.0

4 years ago

2.4.3

4 years ago

2.4.2

4 years ago

2.4.4

4 years ago

2.3.2

4 years ago

2.3.1

4 years ago

2.3.4

4 years ago

2.3.3

4 years ago

2.3.6

4 years ago

2.3.5

4 years ago

2.3.0

4 years ago

2.2.0

4 years ago

2.1.5

4 years ago

2.1.4

4 years ago

2.1.3

4 years ago

2.1.2

4 years ago

2.0.3

4 years ago

2.1.1

4 years ago

2.0.2

4 years ago

2.0.5

4 years ago

2.0.4

4 years ago

2.0.7

4 years ago

2.0.6

4 years ago

2.0.9

4 years ago

2.0.8

4 years ago

2.1.0

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.3.7

4 years ago

1.3.9

4 years ago

1.3.8

4 years ago

1.3.6

4 years ago

1.3.5

4 years ago

1.3.2

4 years ago

1.3.1

4 years ago

1.2.2

4 years ago

1.3.0

4 years ago

1.2.1

4 years ago

1.2.0

4 years ago

1.1.8

4 years ago

1.1.7

4 years ago

1.1.6

4 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.1

4 years ago

1.1.2

4 years ago

1.1.0

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.0

4 years ago