fp-ts is a library for typed functional programming in TypeScript.
Questions tagged [fp-ts]
198 questions
3
votes
1 answer
How do I avoid nested Monads in fp-ts or deal with them elegantly?
I have a sequence of code which needs to go through the below steps (pseudo code):
jobsRepository.findById // <-- this returns a TaskEither
jobs.openJob // <-- jobs.openJob returns an Either
jobsRepository.update // <-- this returns another…

cdimitroulas
- 2,380
- 1
- 15
- 22
2
votes
1 answer
How to collect left values from an array of TaskEithers when using fp-ts?
I have a function that broadcasts an event to my subscribers and the outcome is a TaskEither[]. So far I've been using sequenceArray to map things like this to a TaskEither but in the current case I'd like to gather the…

Adam Arold
- 29,285
- 22
- 112
- 207
2
votes
0 answers
In fp-ts, does the function that applies an Environment to a Reader have a particular (conceptual) name?
In a Reader the E parameter represents the environment to read a value of type A from.
If I have a reader and an environment and would like to read the value from a reader via pipe, one way of doing it is via:
const a = pipe(rdr, I.ap(e))
I…

Carsten
- 468
- 4
- 16
2
votes
1 answer
Using fp-ts sequenceS on Eithers with different left types
I want to use sequenceS function but it does not correctly infer left types. Let's consider the following code:
declare function validateEmail(
email: string
): E.Either
declare function validateUsername(
username:…

David Novák
- 1,455
- 2
- 18
- 30
2
votes
1 answer
How to compose nested Option and Reader?
I have a function that looks up a value from the environment:
type Env = unknown
declare const getFromEnv: (key: string) => Reader>
At the same time I have an array of keys, and I want to look up the value of the last key in…

Mxcpanel
- 95
- 7
2
votes
1 answer
How use Either with async function
I'm learning fp-ts now and try to replace some parts of my API with its approach.
Simple example:
get itemId with request
use this itemId with async function to get (or not) the item
The only way I found is:
const itemId: E.Either

Petr Tcoi
- 53
- 1
- 4
2
votes
1 answer
convert or filter a `Task` from `Some` to `Left` with `fp-ts`
I'm trying to learn how to use type guards and predicted functions with io-ts | fp-ts, and what I need to do the following:
I've this function:
createOne: ({ password, ...creatableUser }: CreatableUser): taskEither.TaskEither

Puszkarek
- 63
- 5
2
votes
1 answer
io-ts logging decoding errors for union types in arrays
I am using io-ts and trying to decode nested arrays of values. The default io-ts behavior is that if any item in an array fails, it fails the whole array. I still wanted the array to pass and only return the valid items and be able to log the…

Brandon
- 187
- 13
2
votes
1 answer
Generic branded types — possible?
I am using io-ts, and I want to do this:
const TokenName = t.brand(
t.string,
(n: unknown): n is t.Branded =>
typeof n === "string", // any name is legit
"TokenName"
);
export type TokenName = t.TypeOf

Michael Lorton
- 43,060
- 26
- 103
- 144
2
votes
1 answer
How to apply a statically typed Record of Functions to an argument in typescript
I have a finite set of function factories with similar return types, each of which returns a crud operation (but could be any operation, for the sake of this question). The return type of operation is Promise, for simplicity.
I want to convert a…

Igor Loskutov
- 2,157
- 2
- 20
- 33
2
votes
2 answers
How to narrow the Option type inferred from fp-ts R.lookup
I am trying to lookup the value of a key with fp-ts. The key might not be present.
type Data = {
a?: number;
b?: string;
c?: { e?: string; w: number };
};
const e = R.lookup('b')({ a: 23, b: 'asdfasdf', c: { e: 'asdf', w: 23}} as Data)
I…

xav
- 4,101
- 5
- 26
- 32
2
votes
1 answer
How to make two parallel requests with different error types using sequenceT and ReaderTaskEither?
I want to make two parallel requests using sequenceT function and work with results, but it shows me an error which I cannot resolve on my own
import * as RTE from 'fp-ts/ReaderTaskEither'
import * as Ap from…

Roman Mahotskyi
- 4,576
- 5
- 35
- 68
2
votes
3 answers
merging 2 TaskEither in fp-ts
I am working on a project that using fp-ts
I have 2 TaskEither object like TaskEither, TaskEither
I wanted to merging this objects contents and create new TaskEither,
Example A object = {a: 123, b: 456, c:…

AlternatifCoplugu
- 33
- 5
2
votes
1 answer
How to turn a TaskOption into a TaskEither using fp-ts?
I have a function that can be used to find an object in the database and returns a TaskOption:
find: (key: SchemaInfo) => TO.TaskOption
and another one that saves it:
register: (schema: Schema) => TE.TaskEither
In my register…

Adam Arold
- 29,285
- 22
- 112
- 207
2
votes
1 answer
fp-ts How to Handle Multiple Eithers with Different Right Types
What is the best way to handle Promises of Eithers when the Right side of the Eithers do not align nicely? In this scenario, I have three non-dependent, "prerequisite" operations represented as Eithers (with different right hand types). If they all…

mattmar10
- 515
- 1
- 4
- 16