How to use the fp-ts.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 devexperts / swagger-codegen-ts / src / language / typescript / 3.0 / serializers / response-object.ts View on Github external
export const serializeResponseObject = (
	from: Ref,
	responseObject: ResponseObject,
): Option> =>
	pipe(
		responseObject.content,
		option.mapNullable(content => content['application/json']),
		option.chain(media => media.schema),
		option.map(schema =>
			ReferenceObjectCodec.is(schema)
				? pipe(fromString(schema.$ref), either.map(getSerializedRefType(from)))
				: serializeSchemaObject(from)(schema),
		),
	);
github devexperts / swagger-codegen-ts / src / language / typescript / 2.0 / serializers / path-item-object.ts View on Github external
export const serializePathItemObjectTags = (pathItemObject: PathItemObject): Option => {
	const operations = [
		pathItemObject.get,
		pathItemObject.post,
		pathItemObject.put,
		pathItemObject.delete,
		pathItemObject.options,
		pathItemObject.head,
		pathItemObject.patch,
	];
	return pipe(
		nonEmptyArray.fromArray(array.compact(operations)),
		option.map(operations => uniqString(flatten(array.compact(operations.map(operation => operation.tags))))),
		option.chain(nonEmptyArray.fromArray),
		option.map(tags => tags.join('').replace(/\s/g, '')),
	);
};
github devexperts / swagger-codegen-ts / src / language / typescript / sketch-121 / serializers / objects / style.ts View on Github external
const backgroundImage = pipe(
		fills,
		option.chain(nonEmptyArray.filter(fill => fill.fillType === 'Gradient')),
		option.map(fills =>
			pipe(
				fills,
				nonEmptyArray.map(fill => serializeGradient(fill.gradient)),
				nonEmptyArray.nonEmptyArray.sequence(either.either),
				either.map(gradients => `backgroundImage: '${gradients.join(', ')}'`),
			),
		),
		sequenceOptionEither,
	);
	const backgroundBlendMode = pipe(
		fills,
		option.map(array.filterMap(fill => option.fromEither(getBackgroundBlendMode(fill.contextSettings.blendMode)))),
		option.chain(array.last),
		option.filter(mode => mode !== 'normal'),
		option.map(mode => `backgroundBlendMode: '${mode}'`),
	);
	const mixBlendMode = pipe(
		style.contextSettings,
		option.chain(settings => option.fromEither(getMixBlendMode(settings.blendMode))),
		option.filter(mode => mode !== 'normal'),
		option.map(mode => `mixBlendMode: '${mode}'`),
	);
	const opacity = pipe(
		style.contextSettings,
		option.map(settings => settings.opacity),
		option.filter(n => n !== 1),
		option.map(opacity => `opacity: '${opacity}'`),
	);
github devexperts / swagger-codegen-ts / src / language / typescript / 2.0 / serializers / paths-object.ts View on Github external
const groupPathsByTag = (pathsObject: PathsObject): Dictionary> => {
	const keys = Object.keys(pathsObject);
	const result: Record = {};
	for (const key of keys) {
		const path = pathsObject[key];
		const tag = pipe(
			serializePathItemObjectTags(path),
			option.map(p => getControllerName(camelize(p, false))),
			option.getOrElse(() => getControllerName('Unknown')),
		);
		result[tag] = {
			...(result[tag] || {}),
			[key]: path,
		};
	}
	return result;
};
github devexperts / swagger-codegen-ts / src / language / typescript / 2.0 / serializers / schema-object.ts View on Github external
record.collect((name, value) => {
								const isRequired = pipe(
									schema.required,
									option.map(includes(name)),
									option.getOrElse(constFalse),
								);
								return pipe(
									serializeSchemaObjectWithRecursion(from, value, false),
									either.map(getSerializedOptionPropertyType(name, isRequired)),
								);
							}),
							sequenceEither,
github devexperts / swagger-codegen-ts / src / language / typescript / sketch-121 / serializers / objects / style.ts View on Github external
const border = pipe(
		borders,
		option.map(array.filterMap(border => option.fromEither(serializeBorder(border, style.borderOptions)))),
		option.chain(array.last),
	);

	const boxShadow = pipe(
		nonEmptyArray.fromArray([
			...innerShadows.map(serializeInnerShadow),
			...array.flatten(array.compact([pipe(shadows, option.map(array.map(serializeShadow)))])),
		]),
		option.map(shadows => `boxShadow: '${shadows.join(', ')}'`),
	);

	const textStyle = pipe(style.textStyle, option.map(serializeTextStyle));

	return combineEither(backgroundImage, backgroundImage =>
		array
			.compact([
				backgroundBlendMode,
				backgroundColor,
				backgroundImage,
				mixBlendMode,
				opacity,
				border,
				boxShadow,
				textStyle,
			])
			.join(', '),
	);
};
github devexperts / swagger-codegen-ts / src / language / typescript / 2.0 / serializers / swagger-object.ts View on Github external
serializePaths => (name: string, swaggerObject: SwaggerObject): Either => {
		const definitions = pipe(
			swaggerObject.definitions,
			option.map(definitions =>
				pipe(
					definitionsRef,
					either.chain(from => serializeDefinitions(from, definitions)),
				),
			),
		);
		const parameters = pipe(
			swaggerObject.parameters,
			option.map(parameters =>
				pipe(
					parametersRef,
					either.chain(ref => serializeParametersDefinitionsObject(ref, parameters)),
				),
			),
		);
		const responses = pipe(
github devexperts / swagger-codegen-ts / src / language / typescript / sketch-121 / serializers / objects / style.ts View on Github external
option.map(fills =>
			pipe(
				fills,
				nonEmptyArray.map(fill => serializeGradient(fill.gradient)),
				nonEmptyArray.nonEmptyArray.sequence(either.either),
				either.map(gradients => `backgroundImage: '${gradients.join(', ')}'`),
			),
		),
		sequenceOptionEither,
	);
	const backgroundBlendMode = pipe(
		fills,
		option.map(array.filterMap(fill => option.fromEither(getBackgroundBlendMode(fill.contextSettings.blendMode)))),
		option.chain(array.last),
		option.filter(mode => mode !== 'normal'),
		option.map(mode => `backgroundBlendMode: '${mode}'`),
	);
	const mixBlendMode = pipe(
		style.contextSettings,
		option.chain(settings => option.fromEither(getMixBlendMode(settings.blendMode))),
		option.filter(mode => mode !== 'normal'),
		option.map(mode => `mixBlendMode: '${mode}'`),
	);
	const opacity = pipe(
		style.contextSettings,
		option.map(settings => settings.opacity),
		option.filter(n => n !== 1),
		option.map(opacity => `opacity: '${opacity}'`),
	);

	const border = pipe(
		borders,
github devexperts / swagger-codegen-ts / src / language / typescript / 3.0 / serializers / paths-object.ts View on Github external
const groupPathsByTag = (pathsObject: PathsObject): Dictionary => {
	const keys = Object.keys(pathsObject);
	const result: Record = {};
	for (const key of keys) {
		const path = pathsObject[key];
		const tag = pipe(
			serializePathItemObjectTags(path),
			option.map(p => getControllerName(camelize(p, false))),
			option.getOrElse(() => getControllerName('Unknown')),
		);
		result[tag] = {
			...(result[tag] || {}),
			[key]: path,
		};
	}
	return result;
};
github devexperts / swagger-codegen-ts / src / language / typescript / 3.0 / serializers / operation-object.ts View on Github external
}

		const serializedQueryParameter = pipe(
			nonEmptyArray.fromArray(serializedQueryParameters),
			option.map(parameters => {
				const intercalated = intercalateSerializedTypes(serializedType(';', ',', [], []), parameters);
				return pipe(intercalated, getSerializedObjectType());
			}),
		);

		const serializedQueryString = pipe(
			nonEmptyArray.fromArray(queryStringFragments),
			option.map(queryStringFragments =>
				intercalateSerializedFragmentsNEA(serializedFragment(',', [], []), queryStringFragments),
			),
			option.map(f =>
				combineFragmentsK(f, c =>
					serializedFragment(
						`encodeURIComponent(compact([${c}]).join('&'))`,
						[serializedDependency('compact', 'fp-ts/lib/Array')],
						[],
					),
				),
			),
		);

		return right({
			pathParameters,
			serializedPathParameters,
			serializedQueryParameter,
			serializedBodyParameter,
			serializedQueryString,