Questions tagged [fp-ts]

fp-ts is a library for typed functional programming in TypeScript.

Links

198 questions
2
votes
1 answer

How to Limit Concurrency in fp-ts

Our team is starting to learn fp-ts, and we are starting with some basic async examples (mostly pulled from here). Running a set of Tasks in sequence is great, and it looks like array.sequence(task)(tasks) The question is, what is the idiomatic way…
Tim
  • 1,013
  • 1
  • 10
  • 16
2
votes
1 answer

Rewriting a small function wrapped with a logger using fp-ts

I wanted to try to rewrite some parts of my code using fp-ts and considered to refactor the following method: export const createApiServer = () => { logger.info("Starting World Server API"); const apiServer = express() // 3rd party…
Christian Ivicevic
  • 10,071
  • 7
  • 39
  • 74
1
vote
1 answer

How to augment 3rd party modules with extra functions when using Typescript?

I have imported a module into the utility library I'm working on with the intent of augmenting and re-exporting it: import * as ITE from "fp-ts/lib/TaskEither"; const foo = () => "foo"; export const TE = { ...ITE, foo }; This works really…
Adam Arold
  • 29,285
  • 22
  • 112
  • 207
1
vote
0 answers

FT-TS how to flatten the left side of TaskEither

Given the following bits: OnRequestSuccess is a async function that does some work and returns a string OnRequestFailure is a async function that does some work and returns a ERROR This is somewhat the desiredFlow. I reckon I could make the fold…
Morphex
  • 306
  • 3
  • 15
1
vote
0 answers

missing types from fp-ts "function" package when used in javascript

I have installed fp-ts in a javascript project with check-js enabaled, but for some reason I can't get the typings for the "fp-ts/function". this is what I get: import {flow} from 'fp-ts/function' //Cannot find module 'fp-ts/function' or its…
Ricardo Silva
  • 1,221
  • 9
  • 19
1
vote
1 answer

Converting an fp-ts Either to an Effect Either

I have been using fp-ts for some time. Lately, I have been thinking about migrating some parts of my codebase to using Effect instead. I'm looking looking for bridges between the two. One of the first obstacles I have run into, is that the Either…
cyberixae
  • 843
  • 5
  • 15
1
vote
1 answer

fp-ts do notation + pipe: multiple binds with spread

I'm trying to figure out how to use fp-ts bind() function to automatically bind multiple properties from an object to the scope in one go: import * as A from "fp-ts/Array"; import * as IO from "fp-ts/IO"; const wrap2 = (x: unknown) => () => () =>…
Adam B.
  • 788
  • 5
  • 14
1
vote
1 answer

How to correctly type a function in io-ts

I have the following: export const ObjC = Codec.struct({ name: Codec.string, value: Codec.number, }) export type ObjType = Codec.TypeOf I want a function for decoding this object and returning an Error (not DecoderError). Similar…
Milk
  • 2,469
  • 5
  • 31
  • 54
1
vote
1 answer

flow input type - why we need to type double array like type[][]?

I'm using functional programming library and there is pipe-like function called flow. It's usage looks like this flow( map(item => item.toString()) )([1, 2, 3]) Flow is generic so it takes in this case 2 type arguments. The first one is for input…
elzoy
  • 5,237
  • 11
  • 40
  • 65
1
vote
2 answers

Generically filtering on an fp-ts Option property and extracting the value

I often find myelf implementing the following pattern when using fp-ts: interface Person { id: number; pet: O.Option<'dog' | 'cat'>; } const person: Person = { id: 1, pet: O.some('dog') }; // simplest case: const maybePersonWithPet =…
Wayne Maurer
  • 12,333
  • 4
  • 33
  • 43
1
vote
1 answer

How to pipe and chain an operation that uses multiple `Eithers` and `Promises` from `fp-ts`

i'm new on fp-ts, i'm trying to create a functional-like method that: Parse a bearer token Check if the user is valid using the parsed token import { Request } from 'express'; import { either } from 'fp-ts'; import { pipe } from…
1
vote
1 answer

typescript - fp ts How to choose a result according of an Option

I'm trying to choose between two possible strings according if an Option is Some or None. When option is Some, everything runs correctly, but when it's none, I'm getting a weird error. import { option } from "fp-ts"; import { pipe } from…
1
vote
1 answer

fp-ts how to prevent traverse from short circuit on Either left?

I have the following code: const tError = (err) => (err instanceof Error ? err : Error("unexpected error")); const safeImport = TE.tryCatchK((s) => import(s)),tError); export const run= (globString) => pipe( glob.sync(globString), …
Ricardo Silva
  • 1,221
  • 9
  • 19
1
vote
1 answer

fp-ts, how to take an array of TaskEithers, run a function in each item then split the options into two arrays?

I am trying to write the following code with fp-ts. imperative: export async function runTest(globString) { let passed = 0; let failed = 0; const files = glob.sync(globString); for (let i = 0; i < files.length; i++) { //…
Ricardo Silva
  • 1,221
  • 9
  • 19