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 |
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$, | |
), | |
), |
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
/** @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 => { |
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 add1 = n => n + 1; | |
const square = n => n * n; | |
// | |
// Array methods | |
// | |
// Each time a method is called, a new array is immediately constructed. | |
[1, 2, 3, 4] |