This file contains 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
// https://gist.github.com/OliverJAsh/5de515ad1f81b88409c13cd548c20893 | |
// https://twitter.com/OliverJAsh/status/1334537098469265413 | |
const { Project } = require('ts-morph'); | |
const project = new Project({ | |
tsConfigFilePath: 'tsconfig.app.no-references.json', | |
}); | |
const PATH_TO_MATCH = '/Users/oliverash/Development/unsplash-web/shared/helpers/booleans.ts'; |
This file contains 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
{ | |
declare const fn: <T>(fn: (t: T) => void, t: T) => void; | |
fn( | |
(t) => { | |
// $ExpectType [number, string] | |
// ❌ | |
// Actual: (string | number)[) | |
t; | |
}, |
This file contains 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 * as Reader from 'fp-ts/lib/Reader'; | |
import { RouteData } from 'helpers/routes/types'; | |
import { pipe, pipeWith } from 'pipe-ts'; | |
// This will soon be part of fp-ts core | |
// https://github.com/gcanti/fp-ts/issues/904#issuecomment-619346296 | |
const chainW: <Q, A, B>( | |
f: (a: A) => Reader.Reader<Q, B>, | |
) => <R>(ma: Reader.Reader<R, A>) => Reader.Reader<R & Q, B> = Reader.chain as Unrestricted; |
This file contains 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 { from } from 'ix/iterable'; | |
import { map } from 'ix/iterable/operators'; | |
const compare = (a: string, b: string) => | |
from(a).pipe(map((value, index) => value === b[index])); | |
for (const v of compare('yes', 'yas')) { | |
console.log(v); | |
} | |
// true |
This file contains 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
describe.only('createDataCron', () => { | |
it( | |
'init', | |
marbles(m => { | |
const source$ = m.cold('--a| '); | |
const sourceS = ' ^------'; | |
const ms = m.time(' ------|'); | |
const expected = ' --a| '; | |
const cron = createDataCron(source$, ms); |
This file contains 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
describe.only('createDataCron', () => { | |
it( | |
'init', | |
marbles(m => { | |
const source$ = m.cold('--a| '); | |
const sourceS = ' ^------'; | |
const ms = m.time(' ------|'); | |
const expected = ' --a| '; | |
const cron = createDataCron(source$, ms); |
This file contains 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
describe.only('createDataCron', () => { | |
it( | |
'init', | |
marbles(m => { | |
const source$ = m.cold('--a| '); | |
const sourceS = ' ^------'; | |
const ms = m.time(' ------|'); | |
const expected = ' --a| '; | |
const cron = createDataCron(source$, ms); |
This file contains 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 getName = async function*() { | |
yield 'bob'; | |
yield 'baz'; | |
yield 'bar'; | |
}; | |
const getAge = (name: string) => { | |
const responseJson = fetch('https://httpbin.org/get') | |
.then(response => response.json()) | |
// Let's pretend the API is returning an age for us |
This file contains 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 { marbles } from 'rxjs-marbles/jest'; | |
import { delayUntil } from '../operators'; | |
describe('delayUntil', () => { | |
it( | |
'if notifier emits nothing and then completes after source emits, emits when notifier completes', | |
marbles(m => { | |
const source$ = m.cold(' --a--(b|)'); | |
const notifier$ = m.cold('----------|'); |
This file contains 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 const delayUntil = <T>( | |
signal$: RxJS.Observable<unknown>, | |
): RxJS.OperatorFunction<T, T> => ob$ => | |
ob$.pipe( | |
RxJSOperators.publishReplay(undefined, undefined, publishedOb$ => | |
RxJS.concat( | |
signal$.pipe(RxJSOperators.first(), RxJSOperators.mergeMapTo(RxJS.EMPTY)), | |
publishedOb$, | |
), | |
), |