Skip to content

Instantly share code, notes, and snippets.

View jurgob's full-sized avatar

Jurgo Boemo jurgob

View GitHub Profile

Exhaustive Pattern Matching in TypeScript

Pattern matching is a powerful programming construct that allows developers to match values against a series of patterns and execute code based on the matched pattern. Exhaustive pattern matching ensures that all possible cases are handled, leaving no room for unintended behavior. In this article, we'll explore exhaustive pattern matching in TypeScript, its importance, and various techniques to achieve it.

Why Exhaustive Pattern Matching?

Exhaustive pattern matching is crucial for writing robust and maintainable code. By ensuring that all possible cases are handled, it helps prevent unexpected runtime errors and makes code more predictable and easier to reason about.

Let's start with an example in Rust to illustrate the concept:

{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "http://json-schema.org/draft-07/schema#",
"title": "Core schema meta-schema",
"components": {
"schemas": {
"uuid": {
"type": "string"
},
"conversation_id": {
{
"id": "<#/components/schemas/event_id>",
"conversation_id": "<#/components/schemas/conversation_id>",
"application_id": "<#/components/schemas/application_id>",
"timestamp": "<#/components/schemas/date>",
"from": "<#/components/schemas/member_id>",
"_embedded": "<#/components/schemas/event_embedded>",
"type": "member:joined",
@jurgob
jurgob / bumpme
Last active August 14, 2020 14:22
bumpme
Fri Aug 14 14:22:51 UTC 2020
import Head from 'next/head'
const TOKEN = "<YOUR USER TOKEN HERE>" //check here for the token creation: https://developer.nexmo.com/client-sdk/tutorials/app-to-phone/client-sdk/generate-jwt
const NexmoMe = ({id, name}) => (
<div>
<b>Name: </b><span>{name}</span><br />
<b>Id: </b><span>{id}</span>
</div>
)
//current:
/*
I m gonna take a simple ncco with is doing a pstn connect.
I m gonna propose how we can instruct it in order to use an exesting converation called "nexmo-permanent-conversation"
*/
/** TODAY */
[
const message = ["Javascript", "Ninja", "Italia"]
const hello = async () => Promise.resolve(message)
.then(([first, ...words]) => {
return `Hello from ${first}(js) ${words}!`
})
const execute = async function() {
const helloString = await hello()
console.log(helloString)
@jurgob
jurgob / run_npe_performance.sh
Last active June 19, 2018 14:38
run_npe_performance.sh
sudo -iu qatests
export PYTHONPATH=~/rtc-performance
cd rtc-performance
git stash
git reset --hard
git checkout master
git pull
pipenv install
sudo -iu qatests
#move Pipfile in the root
pushd ~/rtc-performance
pipenv install
#if NPE
export PYTHONPATH=$PYTHONPATH:$PWD
pipenv run python ./vapi/call_proxy/run_tests.py --rate_initial 2 --rate_max 10 --rate_increment 1 --total 100 --duration 45 --email False --wiki False 2>&1 | tee stress.txt
#to execute copy/paste this capi/cs:
# curl https://gist.githubusercontent.com/jurgob/7b29690416c60eac596c45e937eb8e6b/raw/431947a2189d6897a54ba481104c9cc132ff7b6e/execute_test__cs_capi.sh | bash
sudo -iu qatests
cd /home/qatests/qatests/
export LOCAL_IP=$(npe-node-info-all |grep -A5 loadtest |grep ip|awk '{print $2}')
export PYTHONPATH=/home/qatests/qatests/