Skip to content

Instantly share code, notes, and snippets.

View mvaldesdeleon's full-sized avatar

Martín Valdés de León mvaldesdeleon

View GitHub Profile
newtype Position = (Integer, Integer)
data Replacement = {
rStart :: Position,
rEnd :: Position,
rText :: [Char]
}
data Intersect = BEFORE | INSIDE | AFTER
replace :: [Replacement] -> [Char] -> State Position [Char]
replace _ [] = return []
@mvaldesdeleon
mvaldesdeleon / types-as-sets.ts
Created August 1, 2020 18:32
Types as Sets, draft
// Types as Sets, containing Values
// Union and Intersection Types can be thought as unions and intersections of the underlying Sets
// Type Compatibility can be thought of a subset relationship between the underlying Sets
//
// Usual Set concepts apply, such as:
// cardinality (the number of possible values of a given type)
// ø (empty set)
// unions, intersections, subsets, supersets, sums, products
//
// Lets look at some types...
@mvaldesdeleon
mvaldesdeleon / furvo.js
Created November 25, 2022 16:51
Just some world cup simulations...
let currentScores = {
'arg': 0,
'mex': 1,
'pol': 1,
'ara': 3
}
function updateScores(scores, {home, away, result}) {
scores = {...scores}
@mvaldesdeleon
mvaldesdeleon / object-functions.js
Created August 4, 2018 12:53
General object transformation pattern.
const xxx =
prK =>
prV =>
mapK =>
mapV =>
obj => Object.entries(obj).reduce(
(obj, [key, value]) =>
({
...obj,
...(prK(key) && prV(value) ? {[mapK(key)]: mapV(value)} : {})
type Score = Int
type Rank = Int
climbingLeaderboard :: [Score] -> [Score] -> [Rank]
climbingLeaderboard scores alice = let scoreRank = denseRank scores
aliceDesc = reverse alice
in reverse (rankSeries scoreRank aliceDesc)
denseRank :: [Score] -> [(Rank, Score)]
denseRank scores = go scores 1
@mvaldesdeleon
mvaldesdeleon / building-with-types.ts
Created August 2, 2020 00:20
Building with Types, draft
// Building with Types
// Lets imagine we have two types, for example Number and String.
// In which ways could we combine them, just one of each, to create a different type?
// How could we do this?
// Well... we could create an object:
type Person = {name: string, age: number};
@mvaldesdeleon
mvaldesdeleon / .aws_config
Created November 28, 2019 20:20
"credential_source=Ec2InstanceMetadata" workaround
[profile target-account]
role_arn = arn:aws:iam::123456789012:role/RoleInTargetAccount
source_profile = instance-role
region = eu-central-1
import { Functor3 } from 'fp-ts/lib/Functor'
import { IxMonad3 } from 'fp-ts/lib/IxMonad';
declare module 'fp-ts/lib/HKT' {
// IxBurgerBuilder :: * -> * -> * -> *
interface URI2HKT3<U, L, A> {
IxBurgerBuilder: IxBurgerBuilder<U, L, A>
}
}
// getEmptyPlate :: IxBurgerBuilder Ready EmptyPlate BurgerSpec
// getEmptyPlate = IxBurgerBuilder mempty
const getEmptyPlate = new IxBurgerBuilder<Ready, EmptyPlate, BurgerSpec>([]);
// addIngredient :: forall i o. String -> BurgerSpec -> IxBurgerBuilder i o (BurgerSpec)
// addIngredient x xs = IxBurgerBuilder $ Ingredient x : xs
const addIngredient = <I, O>(s: string) => (spec: BurgerSpec) => new IxBurgerBuilder<I ,O, BurgerSpec>(spec.concat([s]));
// -- ADDING THE BUN
// placeEmptyBun :: BurgerSpec -> IxBurgerBuilder EmptyPlate BottomBunOn BurgerSpec
// -- OUR AMAZING INDEXED BURGER SPEC FROM READY TO TOP BUN ON
// burgerSpec :: IxBurgerBuilder Ready TopBunOn BurgerSpec
// burgerSpec = getEmptyPlate
// :>>= placeEmptyBun
// :>>= addKetchup
// :>>= addPatty
// :>>= addCheese
// :>>= addOnions
// :>>= noLettuce
// :>>= addTomato