How to use the fp-ts/lib/Option.map function in fp-ts

To help you get started, we’ve selected a few fp-ts examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github elastic / kibana / x-pack / legacy / plugins / actions / server / builtin_action_types / webhook.ts View on Github external
if (error.response) {
      const { status, statusText, headers: responseHeaders } = error.response;
      const message = `[${status}] ${statusText}`;
      log(`warn`, `error on ${id} webhook event: ${message}`);
      // The request was made and the server responded with a status code
      // that falls out of the range of 2xx
      // special handling for 5xx
      if (status >= 500) {
        return retryResult(id, message);
      }

      // special handling for rate limiting
      if (status === 429) {
        return pipe(
          getRetryAfterIntervalFromHeaders(responseHeaders),
          map(retry => retryResultSeconds(id, message, retry)),
          getOrElse(() => retryResult(id, message))
        );
      }
      return errorResultInvalid(id, message);
    }

    const message = i18n.translate('xpack.actions.builtin.webhook.unreachableRemoteWebhook', {
      defaultMessage: 'Unreachable Remote Webhook, are you sure the address is correct?',
    });
    log(`warn`, `error on ${id} webhook action: ${message}`);
    return errorResultUnreachable(id, message);
  }
}
github wix / quix / quix-frontend / service / src / modules / web-api / folders / folders.service.ts View on Github external
computePath(fileNode?: DbFileTreeNode): Promise {
    return pipe(
      fromNullable(fileNode),
      map(node => node.mpath.split('.').slice(0, -1)),
      map(async parentsIds => {
        if (parentsIds.length > 0) {
          const parents = await this.fileTreeRepo.getNamesByIds(parentsIds);
          return extractPath(parentsIds, parents);
        }
        return [];
      }),
      getOrElse(() => Promise.resolve([] as IFilePathItem[])),
    );
  }
}
github devexperts / dx-platform / packages / react-kit / src / components / DateInput / DateInput.model.ts View on Github external
export function incrementMonthOption(month: Option): Option {
	return pipe(month, map(incrementMonth), alt(constant(some(0))));
}
github SamHH / bukubrow-webext / src / modules / context.ts View on Github external
getActiveWindowTabs,
			T.map(flow(O.map(sufficientTabsExact), O.chain(NEA.fromArray))),
		);

		case ContextMenuEntry.SendActiveTab: return pipe(
			getActiveTab,
			T.map(flow(
				O.chain(tab => OT.fromNullable(tab.title, tab.url)),
				O.map(([title, url]) => [{ title, url }]),
				O.chain(NEA.fromArray),
			)),
		);

		case ContextMenuEntry.SendLink: return pipe(
			u,
			O.map(url => [{ url, title: url }]),
			O.chain(NEA.fromArray),
			TO.fromOption,
		);

		default: return TO.none;
	}
};
github devexperts / dx-platform / packages / react-kit / src / components / DateInput / DateInput.tsx View on Github external
private renderMonth() {
		const {
			value: { month },
		} = this.props;
		const monthClassName = this.getSectionClassName(ActiveSection.Month);
		const monthValue = map(inc)(month);

		return (
			<span>
				{format(monthValue, ActiveSection.Month)}
			</span>
		);
	}
github SamHH / bukubrow-webext / src / modules / badge.ts View on Github external
export const colors = {
	[URLMatch.Exact]: '#4286f4',
	[URLMatch.Domain]: '#a0c4ff',
};

const hrefToUrlReducer = (acc: Array, href: string): Array =&gt; pipe(
	fromString(href),
	E.fold(
		constant(acc),
		snoc_(acc),
	),
);

const getBookmarksUrlsFromLocalStorage: TaskEither&gt;&gt; = pipe(
	getBookmarksFromLocalStorage,
	TE.map(O.map(flow(
		A.map(bm =&gt; bm.url),
		A.reduce([], hrefToUrlReducer),
	))),
);

let urlState: Array = [];

const syncBookmarks: Task = async () =&gt; {
	const bookmarkUrls = await getBookmarksUrlsFromLocalStorage();

	if (EO.isRightSome(bookmarkUrls)) {
		urlState = bookmarkUrls.right.value;
	}
};

const reduceMatch = ([x, y]: [URLMatch, number]) =&gt; (z: URLMatch): [URLMatch, number] =&gt;
github SamHH / bukubrow-webext / src / modules / context.ts View on Github external
const contextClickTabs = (u: Option) =&gt; (c: ContextMenuEntry): TaskOption&gt; =&gt; {
	switch (c) {
		case ContextMenuEntry.SendAllTabs: return pipe(
			getAllTabs,
			T.map(flow(O.map(sufficientTabsExact), O.chain(NEA.fromArray))),
		);

		case ContextMenuEntry.SendActiveWindowTabs: return pipe(
			getActiveWindowTabs,
			T.map(flow(O.map(sufficientTabsExact), O.chain(NEA.fromArray))),
		);

		case ContextMenuEntry.SendActiveTab: return pipe(
			getActiveTab,
			T.map(flow(
				O.chain(tab =&gt; OT.fromNullable(tab.title, tab.url)),
				O.map(([title, url]) =&gt; [{ title, url }]),
				O.chain(NEA.fromArray),
			)),
		);

		case ContextMenuEntry.SendLink: return pipe(
			u,
			O.map(url =&gt; [{ url, title: url }]),
			O.chain(NEA.fromArray),
			TO.fromOption,
github SamHH / bukubrow-webext / src / apps / content.tsx View on Github external
const ContentApp: FC = () =&gt; {
	const activePage = useSelector(state =&gt; state.user.page);
	const stagedGroupTitle = O.map(formatStagedBookmarksGroupTitle)(useSelector(getStagedGroupToEdit));
	const dispatch = useDispatch();

	const page = pageMap({ activePage, stagedGroupTitle });

	return (
		&lt;&gt;
			

			

			

			
				{'nav' in page &amp;&amp; (
github devexperts / dx-platform / packages / react-kit / src / components / DateInput / DateInput.tsx View on Github external
} else {
					this.onValueChange(day, some(digit - 1), year);
					if (digit &gt; 1) {
						this.selectNextSection();
						this.secondInput = false;
					} else {
						this.secondInput = true;
					}
				}
				break;
			}
			case ActiveSection.Year: {
				if (this.secondInput) {
					const newYear = pipe(
						year,
						map(value =&gt; {
							if (value &lt; 1000) {
								return Number(`${value}${digit}`);
							} else {
								return Number(`${value}${digit}`.substr(1));
							}
						}),
					);
					this.onValueChange(day, month, newYear);
				} else {
					this.onValueChange(day, month, some(digit));
					this.secondInput = true;
				}
				break;
			}
		}
	}
github devexperts / swagger-codegen-ts / src / language / typescript / 2.0 / serializers / path-item-object.ts View on Github external
const run = (from: Ref, url: string, kind: Kind, item: PathItemObject): Either =&gt; {
			if (isSome(item.$ref)) {
				const $ref = item.$ref.value;
				return pipe(
					e.resolveRef($ref, PathItemObjectCodec),
					either.mapLeft(() =&gt; new Error(`Unable to resolve PathItem $ref: "${$ref}"`)),
					either.chain(resolved =&gt; run(from, url, kind, resolved)),
				);
			} else {
				const get = pipe(
					item.get,
					map(operation =&gt; serializeOperationObject(from, url, 'GET', kind, operation, item)),
				);
				const put = pipe(
					item.put,
					map(operation =&gt; serializeOperationObject(from, url, 'PUT', kind, operation, item)),
				);
				const post = pipe(
					item.post,
					map(operation =&gt; serializeOperationObject(from, url, 'POST', kind, operation, item)),
				);
				const remove = pipe(
					item.delete,
					map(operation =&gt; serializeOperationObject(from, url, 'DELETE', kind, operation, item)),
				);
				const options = pipe(
					item.options,
					map(operation =&gt; serializeOperationObject(from, url, 'OPTIONS', kind, operation, item)),
				);
				const head = pipe(
					item.head,
					map(operation =&gt; serializeOperationObject(from, url, 'HEAD', kind, operation, item)),