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
class Functified { | |
constructor(iterable) { | |
this.iterable = iterable; | |
} | |
*[Symbol.iterator]() { | |
for (const value of this.iterable) { | |
yield 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
(() => { | |
const IterableH = { | |
map: fn => iterable => [...iterable].map(fn), | |
}; | |
const MapH = { | |
map: fn => map => new Map(IterableH.map(([ key, value ]) => [ key, fn(value) ])(map)), | |
map2: fn => map => { | |
const newMap = new Map() | |
for ([ key, value ] of map) { |
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
export type Maybe<T> = undefined | T; | |
export type StringDictionary<T> = { [k: string]: T }; | |
export const getInDictionary = <T>(dict: StringDictionary<T>, prop: string): Maybe<T> => dict[prop] | |
export const getInArray = <T>(array: T[], index: number): Maybe<T> => array[index] |
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
{ | |
// Parameter types should not be nullable | |
// https://github.com/facebook/immutable-js/pull/919 | |
const xs: List<number> = List([1]) | |
xs.forEach(x => { | |
x // number | undefined, should be number | |
}) | |
// Workaround: | |
xs.forEach((x: number) => { | |
x // 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
const reportFetchAction = (result?: Result<Report>): ReportFetch => ( | |
{ type: ActionType.ReportFetch, result } | |
); | |
// fetchReport = (id: number) => Observable<Result<Report>> | |
const runFetchReportData = (id: number): Observable<ReportFetch> => { | |
const report$: Observable<Result<Report>> = fetchReport(id) | |
return Observable.of(reportFetchAction()).concat(report$.map(reportFetchAction)) | |
} | |
type State = { reportId: 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
// findPersonWithName = string => Person | undefined; | |
// findParentForPerson = Person => Person | undefined; | |
// isOver50 = Person => boolean; | |
// isSubscribed = Person => boolean; | |
// Without Options | |
// In TS1 this is not type safe, in TS2 it is | |
const person = findPersonWithName('bob') | |
const parent = person !== undefined ? findParentForPerson(person) : undefined; | |
const parentOver50 = parent !== undefined ? (isOver50(parent) ? parent : undefined) : undefined; |
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 f = (c: number): Option<number> => c === 2 ? Some(c) : None | |
const add1 = (c: number): number => c + 1; | |
const maybeNumber = Option(1) | |
maybeNumber.flatMap(f).map(add1).getOrElse(5) | |
})() | |
(() => { | |
const f = (c: number): number | undefined => c === 2 ? c : undefined; | |
const add1 = (c: number): number => c + 1; |
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
#compdef git-apply-pr | |
_git-apply-pr() { | |
_git-branch | |
} |
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
System.config({ | |
baseURL: "/", | |
defaultJSExtensions: true, | |
transpiler: "babel", | |
babelOptions: { | |
"optional": [ | |
"runtime", | |
"optimisation.modules.system" | |
] | |
}, |
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 domContentLoaded = 'DOMContentLoaded'; | |
const promise = new Promise((resolve, reject) => { | |
let loaded = /^loaded|^i|^c/.test(document.readyState); | |
if (loaded) { | |
resolve(); | |
} else { | |
const listener = () => { | |
// If an async error occurs we want to push it to the promise | |
try { |