本文整理汇总了TypeScript中spica/maybe.Just函数的典型用法代码示例。如果您正苦于以下问题:TypeScript Just函数的具体用法?TypeScript Just怎么用?TypeScript Just使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Just函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: pair
function pair(area: AreaRecord): Maybe<AreaRecord> {
return Just(area)
.guard(validate(area));
function validate(area: AreaRecord): boolean {
return area.src.length > 0
&& area.src.length === area.dst.length;
}
}
示例2: sep
function sep(documents: DocumentRecord, area: string): Maybe<AreaRecord[]> {
return split(area)
.map(area => ({
src: find(documents.src, area),
dst: find(documents.dst, area)
}))
.reduce<Maybe<AreaRecord[]>>((acc, area) =>
acc
.bind(as =>
pair(area)
.fmap(a =>
concat(as, [a])))
, Just([]));
function pair(area: AreaRecord): Maybe<AreaRecord> {
return Just(area)
.guard(validate(area));
function validate(area: AreaRecord): boolean {
return area.src.length > 0
&& area.src.length === area.dst.length;
}
}
}
示例3: route
export function route(
config: Config,
event: RouterEvent,
process: Supervisor<'', Error>,
io: {
document: Document;
}
): boolean {
assert([HTMLAnchorElement, HTMLFormElement, Window].some(Class => event.source instanceof Class));
switch (event.type) {
case RouterEventType.click:
case RouterEventType.submit:
void savePosition();
break;
case RouterEventType.popstate:
io.document.title = loadTitle();
break;
}
return Just(0)
.guard(validate(event.request.url, config, event))
.bind(() =>
scope(config, (({ orig, dest }) => ({ orig: orig.pathname, dest: dest.pathname }))(event.location)))
.fmap(async config => {
void event.original.preventDefault();
void process.cast('', new Error(`Aborted.`));
const cancellation = new Cancellation<Error>();
const kill = process.register('', e => {
void kill();
void cancellation.cancel(e);
return new Promise<never>(() => undefined);
}, undefined);
const [scripts] = await env;
window.history.scrollRestoration = 'manual';
//void progressbar(config.progressbar);
return router(config, event, { process: cancellation, scripts }, io)
.then(m => m
.fmap(async ([ss, p]) => (
void kill(),
void docurl.sync(),
void ss
.filter(s => s.hasAttribute('src'))
.forEach(s =>
void scripts.add(new URL(standardize(s.src)).reference)),
void (await p)
.filter(s => s.hasAttribute('src'))
.forEach(s =>
void scripts.add(new URL(standardize(s.src)).reference))))
.extract())
.catch(reason => (
void kill(),
void docurl.sync(),
window.history.scrollRestoration = 'auto',
!cancellation.canceled || reason instanceof FatalError
? void config.fallback(currentTargets.get(event.original) as RouterEventSource, reason)
: undefined));
})
.extract(
() => {
switch (event.type) {
case RouterEventType.click:
case RouterEventType.submit:
break;
case RouterEventType.popstate:
if (!isHashChange(event.location.dest)) {
void config.fallback(event.source, new Error(`Disabled.`));
return true;
}
break;
}
void docurl.sync();
return false;
},
() => true);
}
示例4: Just
.map<Maybe<Config>>(option =>
option
? Just(new Config(extend<Option>({}, config, option)))
: Nothing)