This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const esRoja = carta => carta.endsWith('c') || carta.endsWith('d'); | |
| const cartas = [ | |
| "1c","2c","3c","4c","5c","6c","7c","8c","9c","10c","11c","12c", | |
| "1d","2d","3d","4d","5d","6d","7d","8d","9d","10d","11d","12d", | |
| "1t","2t","3t","4t","5t","6t","7t","8t","9t","10t","11t","12t", | |
| "1p","2p","3p","4p","5p","6p","7p","8p","9p","10p","11p","12p" | |
| ]; | |
| const cartasRojas = cartas.filter(esRoja); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| data Instruction = F | B | L | R | |
| data Direction = N | S | E | W | |
| deriving Eq | |
| data Position = Position Integer Integer | |
| deriving Eq | |
| data WorldState = WorldState { roverPosition :: Position, roverDirection :: Direction, width :: Integer, height :: Integer, obstacles :: [Position] } | |
| deriving Eq | |
| step :: WorldState -> Instruction -> WorldState |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const xxx = | |
| prK => | |
| prV => | |
| mapK => | |
| mapV => | |
| obj => Object.entries(obj).reduce( | |
| (obj, [key, value]) => | |
| ({ | |
| ...obj, | |
| ...(prK(key) && prV(value) ? {[mapK(key)]: mapV(value)} : {}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| interface INothing { | |
| _: 'Nothing'; | |
| } | |
| interface IJust<A> { | |
| _: 'Just'; | |
| value: A; | |
| } | |
| type Maybe<A> = INothing | IJust<A>; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import fl = require('fantasy-land'); | |
| interface ILeft<A> { | |
| _: 'Left'; | |
| value: A; | |
| } | |
| interface IRight<B> { | |
| _: 'Right'; | |
| value: B; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| interface Monoid<A, B> { | |
| mempty: () => Monoid<A, B>; | |
| mconcat: (r: Monoid<A, B>) => Monoid<A, B>; | |
| runMonoid: () => B; | |
| } | |
| const mconcat = <A, B>(a : Monoid<A, B>) => (b: Monoid<A, B>): Monoid<A, B> => a.mconcat(b); | |
| class Sum implements Monoid<Sum, number> { | |
| constructor(private value: number) {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| interface Monoid<A> { | |
| empty: () => A; | |
| concat: (a: A) => A; | |
| } | |
| class Sum implements Monoid<Sum> { | |
| public static of(value: number) { | |
| return new Sum(value); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| interface MonoidCtor<A> { | |
| new (a: any): Monoid<A>; | |
| of (value: any): Monoid<A>; | |
| empty (): Monoid<A>; | |
| concat: (a: Monoid<A>) => (b: Monoid<A>) => Monoid<A>; | |
| } | |
| interface Monoid<A> { | |
| empty: () => A; | |
| concat: (a: A) => A; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| interface MonoidCtor<A> { | |
| new (a: any): Monoid<A>; | |
| of (value: any): Monoid<A>; | |
| empty (): Monoid<A>; | |
| concat: (a: Monoid<A>) => (b: Monoid<A>) => Monoid<A>; | |
| } | |
| interface Monoid<A> { | |
| empty: () => Monoid<A>; | |
| concat: (a: Monoid<A>) => Monoid<A>; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| interface MonoidCtor<A> { | |
| new (a: any): Monoid<A>; | |
| of (value: any): Monoid<A>; | |
| empty (): Monoid<A>; | |
| concat: (a: Monoid<A>) => (b: Monoid<A>) => Monoid<A>; | |
| reify: (a: Monoid<A>) => A; | |
| } | |
| interface Monoid<A> { | |
| empty: () => A; |