How to use the fp-ts/lib/Option.getOrElse 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
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 marblejs / marble / packages / messaging / src / client / messaging.client.ts View on Github external
return pipe(reader, R.map(ask => {
    const transportLayer = provideTransportLayer(transport, options);
    const connection = transportLayer.connect({ isConsumer: false });

    pipe(
      ask(ServerEventStreamToken),
      O.map(teardownOnClose$(connection)),
      O.getOrElse(() => EMPTY as Observable),
    ).subscribe();

    return {
      emit: emit(connection),
      send: send(connection),
      close: close(connection),
    } as MessagingClient;
  }));
};
github tangdrew / fhir-ts / packages / fhir-ts-codegen / lib / parser.ts View on Github external
const getLastPathStep = (path: string) =>
  pipe(
    path.split("."),
    last,
    O.getOrElse(() => "")
  );
github devexperts / swagger-codegen-ts / src / utils / utils.ts View on Github external
export const getOperationParametersInBody = (operation: OperationObject): BodyParameterObject[] =>
	pipe(
		operation.parameters,
		map(parameters => parameters.filter(isOperationBodyParameterObject)),
		getOrElse(constant([])),
	);
github stoplightio / prism / packages / http / src / mocker / index.ts View on Github external
O.mapNullable(request => request.body),
    O.mapNullable(body => body.contents),
    O.getOrElse(() => [] as IMediaTypeContent[])
  );

  const encodedUriParams = splitUriParams(request.body as string);

  if (specs.length < 1) {
    return Object.assign(request, { body: encodedUriParams });
  }

  const content = pipe(
    O.fromNullable(mediaType),
    O.chain(mediaType => findContentByMediaTypeOrFirst(specs, mediaType)),
    O.map(({ content }) => content),
    O.getOrElse(() => specs[0] || {})
  );

  const encodings = get(content, 'encodings', []);

  if (!content.schema) return Object.assign(request, { body: encodedUriParams });

  return Object.assign(request, {
    body: deserializeFormBody(content.schema, encodings, decodeUriEntities(encodedUriParams)),
  });
}
github devexperts / dx-platform / packages / react-kit / src / components / TimeInput / TimeInput.model.ts View on Github external
export function togglePeriodType(periodType: Option): Option {
	const periodTypeNormalized = getOrElse(() => PeriodType.AM)(periodType);
	switch (periodTypeNormalized) {
		case PeriodType.AM:
			return some(PeriodType.PM);
		case PeriodType.PM:
			return some(PeriodType.AM);
	}
}
github gcanti / fp-ts-codegen / src / ast.ts View on Github external
d.parameterDeclarations.map(p =>
      pipe(
        p.constraint,
        O.map(c => getTypeNode(c)),
        O.getOrElse(() => ts.createKeywordTypeNode(ts.SyntaxKind.NeverKeyword))
      )
    )
github devexperts / swagger-codegen-ts / src / language / typescript / 2.0-rx / serializers / body-parameter-object.ts View on Github external
const serializeBodyParameterObject = (
	parameter: BodyParameterObject,
	rootName: string,
	cwd: string,
): Either => {
	const isRequired = pipe(
		parameter.required,
		getOrElse(constFalse),
	);
	return pipe(
		serializeSchemaObject(parameter.schema, rootName, cwd),
		either.map(serializedParameterType =>
			serializedParameter(
				serializedParameterType.type,
				serializedParameterType.io,
				isRequired,
				serializedParameterType.dependencies,
				serializedParameterType.refs,
			),
		),
	);
};
github gcanti / fp-ts-codegen / src / printer.ts View on Github external
R.map(functionDeclaration =>
      pipe(
        functionDeclaration,
        O.map(ast),
        O.getOrElse(() => '')
      )
    )
github rzeigler / waveguide / src / wave.ts View on Github external
export function encaseOption(o: Option<a>, onError: Lazy): Wave {
  return pipe(o,
    option.map&gt;(pure),
    option.getOrElse&gt;(() =&gt; raiseError(onError())));
}
</a>