Skip to content

Instantly share code, notes, and snippets.

@fvilante
fvilante / aFunc.js
Created March 11, 2019 02:14
Article Test
let f = x => x
// 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
/*
const Url =
Safe<string>({
validation: [] //fix: introduce validation
validOperations: [getfullPath]
}
*/
// assures T is a primitive type
import { mapObjIndexed } from 'ramda'
type PropMorphism
<TKeyValue, TContext extends object, TKeyName, TResult> =
(value: TKeyValue, context: TContext, keyname: TKeyName) =>
TResult
/**
* Use HasExactlySameKeys if you want to assure to procced
// Demonstration of Core Concepts
// Event Source Reducer functional style and typesafe
// =========================
// Lib Event Source
// =========================
type UserDocument = object
type State = ReadonlyArray<object>
@fvilante
fvilante / Functor.ts
Created April 18, 2019 21:58
An example of Functor in TypeScript. You can run this on https://www.typescriptlang.org/play/
// ==============================================
// PROPOSAL OF SOLUTION
// ==============================================
// ================================
// Emulate nominal type-system
// ================================
type Kind<K> = { kind: K }
type Value<T> = { value: T }
@fvilante
fvilante / MessageDispatcher.ts
Last active May 9, 2019 07:19
Modeling of parametrized Messages and a Generic Dispatcher
// ============================================================
// Sample code:
// Modeling of parametrized Messages and a Generic Dispatcher
//
// Author: @fvilante
// ============================================================
// Messages (or events, or actions...)
@fvilante
fvilante / Pipe.ts
Last active August 17, 2019 01:40
Function composition
// A 100% type-safe solution to compose functions in typescript
// tested in TS 3.5.1
type Func<A, B> = (_: A) => B
class ComposedFn<A, B> {
constructor(private f: Func<A, B>) { }
static of = <A,B>(fn: Func<A, B>): ComposedFn<A, B> =>
new ComposedFn(fn)
interface Entry {
value: string
label: string
}
type Dictionary = Entry[]
const dictionary: Dictionary = [
{ value: 'primeiro', label: '1 - Primeiro' },
{ value: 'segundo', label: '2 - Segundo' },
@fvilante
fvilante / CrazyFunctor.ts
Created May 14, 2019 15:36
Don't know why but this seems very impressive to me
// Don't know why but this seems very impressive to me
type Func<A, B> = (_: A) => B
class Value<A> {
constructor(private _content: A ) { }
static of = <A>(data: A): Value<A> => new Value(data)