Skip to content

Instantly share code, notes, and snippets.

/*
const Url =
Safe<string>({
validation: [] //fix: introduce validation
validOperations: [getfullPath]
}
*/
// assures T is a primitive type
// assures T is a primitive type
type TPrimitive<T> =
T extends number ? number :
T extends string ? string :
// object, array, etc . . .
// else
never
type Safe<TKind extends string, T> = {
kind: TKind
@fvilante
fvilante / aFunc.js
Created March 11, 2019 02:14
Article Test
let f = x => x
namespace mapStream_ {
export interface EventGenerator {
onEvent: (h: EventHandler) => void
}
type Food = string
export type Event = Food
@fvilante
fvilante / TypeParameterNamingConventionsStudy.ts
Last active March 5, 2019 06:11
Comparisson of alternative type parameter naming in Typescript
// A study on alternative forms to name Typescript Type parameters
// original thread: https://twitter.com/sompylasar/status/1102446254292983808
// *********************************
// T,U,V convention
// *********************************
@fvilante
fvilante / patternMatch.ts
Last active September 17, 2019 20:17
Pattern Match
namespace Maybe_ {
type Undefined = typeof Undefined
const Undefined = Symbol.for("None") // undefined
interface Just<T> {
readonly type: "Just",
readonly val: T | Undefined
}
@fvilante
fvilante / maptree.ts
Last active March 27, 2019 21:01
TS Algorithms
interface Node_<T> {
readonly value: T
readonly childreen: ReadonlyArray<Node_<T>> | undefined
}
const state: Node_<string> = {
value: "foo",
childreen: [
{
namespace Maybe_ {
type n = Extract
type Undefined = typeof Undefined
const Undefined = Symbol.for("None") // undefined
@fvilante
fvilante / filterArraysRamda.md
Created January 8, 2019 10:41 — forked from cezarneaga/filterArraysRamda.md
Filter array of objects by nested values using ramda: Sometimes you dont have access to backend and you want to filter the response from an endpoint based on certain criteria. While trivial on flat arrays, this gets a bit tricky if the property you want to query is deeply nested. This is where Ramda shines.

Say we have a prop.users of the shape:

const users = [
    {username: 'bob', age: 30, tags: [{name: 'work', id: 1}, {name: 'boring', id: 2}]},
    {username: 'jim', age: 25, tags: [{name: 'home', id: 3}, {name: 'fun', id: 4}]},
    {username: 'jane', age: 30, tags: [{name: 'vacation', id: 5}, {name: 'fun', id: 4}]}
];
@fvilante
fvilante / example.js
Created January 4, 2019 23:34
Application Instantiation
// an organized way to initialize your application
// extract from this article: https://medium.freecodecamp.org/why-you-should-use-functional-composition-for-your-full-applications-eb7b702ffd4a
import config from './config';
import Database from './Database';
import Models from './Models';
import Server from './Server';
function startApplication() {
const env = config();