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
fibs :: Num a => [a]
fibs = 0 : 1 : zipWith (+) fibs (tail fibs)
isEven :: Integral a => a -> Bool
isEven x = x `mod` 2 == 0
main :: IO ()
main = print $ takeWhile (\x -> x <= 4000000) (filter isEven fibs)
-- [0,2,8,34,144,610,2584,10946,46368,196418,832040,3524578]
interface Boring {
bore: () => boolean
}
interface Fooable<A> {
foo: () => string,
unfoo: (s: string) => A
}
interface Barable<A> {
// data Ready
// data EmptyPlate
// data BottomBunOn
// data PattyOn
// data CheeseOn
// data OnionOn
// data LettuceOn
// data TomatoOn
// data PicklesOn
// data TopBunOn
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
// -- EXAMPLE THAT WOULD BE WRONG
// -- wrongBurgerSpec :: IxBurgerBuilder Ready TopBunOn BurgerSpec
// -- wrongBurgerSpec = getEmptyPlate
// -- :>>= placeEmptyBun
// -- :>>= addKetchup
// -- :>>= addCheese -- Can't match PattyOn with BottomBunOn, since we haven't put on the patty, the most important part!!!
// -- :>>= addOnions
// -- :>>= noLettuce
// -- :>>= addTomato
// -- :>>= addTopBun
asInt :: String -> Either String Int
asInt ('-':xs) = negate <$> asInt xs
asInt xs =
foldl
(\acc x -> acc >>= addNextDigit x)
(Right 0)
xs
where addNextDigit x acc = if isDigit x
then Right $ acc * 10 + digitToInt x
else Left $ "non-digit"
function mapCompose<A, B, C>(mab: Map<A, B>, mbc: Map<B, C>): Map<A, C> {
const mac: Map<A, C> = new Map();
mab.forEach((value, key) => {
const finalValue = mbc.get(value);
if (finalValue !== undefined) {
mac.set(key, finalValue);
}
});
@mvaldesdeleon
mvaldesdeleon / .gitignore
Created November 13, 2018 21:35
gitignore all the things (...)
# See http://help.github.com/ignore-files/ for more about ignoring files.
# IDEs and editors
.idea/*
**/.idea/*
!.idea/codeStyleSettings.xml
!.idea/watcherTasks.xml
.project
.classpath
.c9/