fp-ts is a library for typed functional programming in TypeScript.
Questions tagged [fp-ts]
198 questions
11
votes
1 answer
Chain some async tasks in fp-ts retaining every task's result
In fp-ts, I'm trying to chain some potentially failing async tasks together with TaskEither but I need to use the results from intermediate tasks later on down the chain.
In this example:
const getFoo = (a: string): Promise => {};
const getBar…

ironchicken
- 754
- 6
- 19
10
votes
1 answer
higher kinded type in typescript from fp-ts and URI
In fp-ts they have this workaround for higher kinded types:
export interface HKT {
readonly _URI: URI;
readonly _A: A;
}
And it can be used like this:
export interface Foldable {
readonly URI: F;
reduce: (fa: HKT, b:…

dagda1
- 26,856
- 59
- 237
- 450
9
votes
2 answers
Convert Array of Either to Either (sequence function in Scalaz)
I am still learning and playing with fp-ts and can't figure this out.
I have an array of Either[] and I would like to get an Either.
I have looked at Apply.sequenceT and the example sequenceToOption and it looks…

anotherhale
- 175
- 1
- 6
6
votes
1 answer
How to flatten TaskEither> in FP-TS
I am new to fp-ts. I am used to scala for comprehensions when dealing with combining Either, IO and ...
The question is, let's say we have function with signatures
either(T): Either
ioEither(T): IOEither
taskEither(T):…

Danil
- 103
- 7
6
votes
1 answer
How to transform a JS array of strings into a union with io-ts?
I'm using io-ts and i'm wondering if there's a way to turn an array of strings (literals) into a union of such literals. For example:
export const CONTROLS = [
"section",
"text",
"richtext",
"number",
];
export const ControlType = t.union(
…

Obed Parlapiano
- 3,226
- 3
- 21
- 39
6
votes
2 answers
Io-ts interface for properties with unknown keys
I'm trying to create an io-ts interface of the following:
export interface myInterface {
[key:string]?: string | undefined | null
}
I want to turn this into the io-ts equivalent. The end goal is to combine it with another existing io-ts…

jbailie1991
- 1,305
- 2
- 21
- 42
6
votes
1 answer
Lazily evaluated recursive stream in fp-ts from paginated API
My goal is to request transactions from an API and store them to a database. The response is paginated and I want to read every page and store the transactions in batches.
So for one request/response cycle I wish to then process the result and store…

Magnus
- 3,691
- 5
- 27
- 35
5
votes
1 answer
FP-TS Branching (Railway Oriented Programming)
A pattern I keep encountering trying to implement things using FP-TS is when I have pipes that involve branching and merging branches of TaskEither together.
Merging seems to work quite well, because I can use sequenceT to create arrays and pipe…

Richard Howell-Peak
- 417
- 4
- 11
5
votes
1 answer
fp-ts Return all left values from an Either[] sequence
I have a list of strings, string[]
I map a validate function that returns Either[]
I want [Error[], string[]], all validation errors and all validated strings.
Can sequence(Either.Applicative) or traverse(Either.Applicative) return…

steve76
- 302
- 2
- 9
5
votes
1 answer
Running an array of TaskEithers in parallel, but continue if 1 or more task fails
I have to make an array of IO calls in parallel, and merge the contents of the call if successful. If one fails the others get processed as per normal, but an error message.
My thought process on how this can be implemented:
Array> -> TE

iflp
- 1,742
- 17
- 25
5
votes
1 answer
How to chain dependent TaskEither operations in FP-TS
I am new to FP-TS and still don't quite understand how to work with TaskEither. I am attempting to asynchronously read a file and then parse the resulting string with yaml-parse-promise.
==EDIT==
I updated the code with the full contents of the file…

anotherhale
- 175
- 1
- 6
4
votes
1 answer
Mixing Either and TaskEither in a pipe in fp-ts
I have the following program that works fine when none of the functions is async.
interface Product {
count: number
pricePerItem: number
}
interface Tax {
tax: number
}
interface Delivery {
delivery: number
}
interface PTD {…

Kevin Le - Khnle
- 10,579
- 11
- 54
- 80
4
votes
2 answers
How to "widen" reader type when using fp-ts sequenceT?
I'm wondering if it's possible to "widen" my ultimate Reader type when using sequenceT? This is possible when chaining operations sequentially using chainW etc., but it looks like when using sequenceT you're stuck with every item having to use the…

Jess
- 387
- 1
- 4
- 9
4
votes
6 answers
alternative to switch statement for typescript discriminated union
I have created this playground and here is the code:
type BundlerError = Error;
type BundlerWarning = Error;
export type BundlerState =
| { type: 'UNBUNDLED' }
| { type: 'BUILDING'; warnings: BundlerWarning[] }
| { type: 'GREEN'; path:…

dagda1
- 26,856
- 59
- 237
- 450
4
votes
1 answer
Chain fp-ts TaskEither with Either in right
I have a flow of 2 nested request, where could be 3 different results:
One of requests return Error
User is not Anonymous, return Profile
User is Anonymous, return false
Both requests could throw an error, and becaues of that implements…

Ivan Tarasov
- 85
- 1
- 3