Skip to content

Instantly share code, notes, and snippets.

View foo.ts
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;
View foo.ts
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
View foo.ts
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);
View foo.ts
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);
View foo.ts
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);
@OliverJAsh
OliverJAsh / example.ts
Last active Mar 31, 2020
async iterable operators (map, filter) using async generators
View example.ts
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
View foo.ts
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('----------|');
View foo.ts
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$,
),
),
@OliverJAsh
OliverJAsh / foo.md
Last active Apr 15, 2020
`Option` vs non-`Option`
View foo.md

Option vs non-Option

Option<T> non-Option (T | undefined)
accessing property userOption.map(user => user.age) userNullish?.age
calling a method userOption.map(user => user.fn()) userNullish?.fn()
providing fallback ageOption.getOrElse(0) ageNullish ?? 0
filter ageOption.filter(checkIsOddNumber) `ageNull
@OliverJAsh
OliverJAsh / foo.js
Created Jan 22, 2020
ESLint `no-logical-not`
View foo.js
/** @type {import('eslint').Rule.RuleModule} */
const noLogicalNot = {
meta: { fixable: 'code' },
create: context => {
/** @type {(node: import('estree').Node) => void} */
const listener = node => {
context.report({
node,
message: 'Prefer `x === false`.',
fix: fixer => {
You can’t perform that action at this time.