How to use the fp-ts/lib/Either.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 stoplightio / prism / packages / http / src / mocker / negotiator / NegotiatorHelpers.ts View on Github external
content => {
              logger.success(`Found a compatible content for ${mediaTypes}`);
              // a httpContent for a provided mediaType exists
              return pipe(
                helpers.negotiateByPartialOptionsAndHttpContent(
                  {
                    code,
                    dynamic,
                    exampleKey,
                  },
                  content
                ),
                E.map(contentNegotiationResult => ({
                  headers: headers || [],
                  ...contentNegotiationResult,
                  mediaType:
                    contentNegotiationResult.mediaType === '*/*' ? 'text/plain' : contentNegotiationResult.mediaType,
                }))
              );
            }
          )
github teves-castro / ts-do / test / Either.spec.ts View on Github external
it("chains scoped computations", () => {
      const result = pipe(
        right(10),
        into("x"),
        bind("y", ({ x }) => right(x - 5)),
        map(({ x, y }) => x - y),
      )

      expect(result).toEqual(right(5))
    })
github stoplightio / prism / packages / http / src / validator / validators / body.ts View on Github external
function deserializeAndValidate(content: IMediaTypeContent, schema: JSONSchema, target: string) {
  const encodings = get(content, 'encodings', []);
  const encodedUriParams = splitUriParams(target);

  return pipe(
    validateAgainstReservedCharacters(encodedUriParams, encodings),
    E.map(decodeUriEntities),
    E.map(decodedUriEntities => deserializeFormBody(schema, encodings, decodedUriEntities)),
    E.chain(deserialised =>
      pipe(
        validateAgainstSchema(deserialised, schema, true),
        E.fromOption(() => deserialised),
        E.swap
      )
    )
  );
}
github gcanti / docs-ts / src / parser.ts View on Github external
!isInternal(annotation) &&
          initializer !== undefined &&
          vs.isExported() &&
          ast.TypeGuards.isFunctionLikeDeclaration(initializer)
        )
      }
    }
    return false
  })

  const variableDeclarations = traverse(exportedVariableDeclarations, parseFunctionVariableDeclaration)

  const monoidFunc = E.getValidationMonoid(monoidFailure, A.getMonoid())
  return pipe(
    monoidFunc.concat(functionDeclarations, variableDeclarations),
    E.map(funcs => funcs.sort(byName.compare))
  )
}
github gcanti / docs-ts / src / parser.ts View on Github external
export function getInterfaces(sourceFile: ast.SourceFile): Parser> {
  const exportedInterfaceDeclarations = sourceFile.getInterfaces().filter(id => id.isExported())
  return pipe(
    traverse(exportedInterfaceDeclarations, parseInterfaceDeclaration),
    E.map(interfaces => interfaces.sort(byName.compare))
  )
}
github elastic / kibana / x-pack / legacy / plugins / infra / server / lib / log_analysis / log_analysis.ts View on Github external
endTime,
          bucketDuration,
          COMPOSITE_AGGREGATION_BATCH_SIZE,
          afterLatestBatchKey
        )
      );

      if (mlModelPlotResponse._shards.total === 0) {
        throw new NoLogRateResultsIndexError(
          `Failed to find ml result index for job ${logRateJobId}.`
        );
      }

      const { after_key: afterKey, buckets: latestBatchBuckets } = pipe(
        logRateModelPlotResponseRT.decode(mlModelPlotResponse),
        map(response => response.aggregations.timestamp_data_set_buckets),
        fold(throwErrors(createPlainError), identity)
      );

      mlModelPlotBuckets = [...mlModelPlotBuckets, ...latestBatchBuckets];
      afterLatestBatchKey = afterKey;

      if (latestBatchBuckets.length < COMPOSITE_AGGREGATION_BATCH_SIZE) {
        break;
      }
    }

    return mlModelPlotBuckets.reduce<
      Array<{
        dataSets: Array<{
          analysisBucketCount: number;
          anomalies: Array<{
github elastic / kibana / x-pack / legacy / plugins / siem / server / lib / pinned_event / saved_object.ts View on Github external
const convertSavedObjectToSavedPinnedEvent = (
  savedObject: unknown,
  timelineVersion?: string | undefined | null
): PinnedEventSavedObject =>
  pipe(
    PinnedEventSavedObjectRuntimeType.decode(savedObject),
    map(savedPinnedEvent => ({
      pinnedEventId: savedPinnedEvent.id,
      version: savedPinnedEvent.version,
      timelineVersion,
      ...savedPinnedEvent.attributes,
    })),
    fold(errors => {
      throw new Error(failure(errors).join('\n'));
    }, identity)
  );
github gcanti / elm-ts / src / Debug / redux-devtool.ts View on Github external
function parseToggleAction(msg: Monitor): Either]> {
  const getId = pipe(
    msg.payload.id,
    E.fromNullable('TOGGLE_ACTION message has some bad payload...'),
    E.map(x => x)
  )

  const parseState = pipe(
    E.parseJSON(msg.state, E.toError),
    E.bimap(e => e.message, u => u as LiftedState)
  )

  return sequenceTEither(getId, parseState)
}
github gcanti / docs-ts / src / parser.ts View on Github external
const annotation = getAnnotation(vs.getJsDocs())
        const initializer = vd.getInitializer()
        return (
          !isInternal(annotation) &&
          initializer !== undefined &&
          vs.isExported() &&
          !ast.TypeGuards.isFunctionLikeDeclaration(initializer)
        )
      }
    }
    return false
  })

  return pipe(
    traverse(exportedVariableDeclarations, parseConstantVariableDeclaration),
    E.map(constants => constants.sort(byName.compare))
  )
}