fp-ts is a library for typed functional programming in TypeScript.
Questions tagged [fp-ts]
198 questions
2
votes
1 answer
fp-ts How to Handle Async operations within pipe
I'm learning fp-ts and am wondering how can I better organize my functions to avoid nested folds. All of the examples I see online have a nice streamlined pipe function invocation, but I can't figure out how to avoid the nested folds.
Some context -…

mattmar10
- 515
- 1
- 4
- 16
2
votes
1 answer
How to properly type fp-ts ObservableEither#fold?
I'm attempting to use fp-ts and redux-observable to build some epics that process some api requests. I am having an issue with fp-ts-rxjs/ObservableEither#fold where if I do not cast my actions into type AnyAction I get a type error saying that the…

George S
- 323
- 3
- 15
2
votes
1 answer
Refactoring after deprecation of getFoldableComposition, option, array et al
I spent some time last year trying to learn fp-ts. I've finally come around to using it in a project and a lot of my sample code has broken due to the recent refactoring. I've fixed a few of the breakages but am strugging with the others. It…

Damien Sawyer
- 5,323
- 3
- 44
- 56
2
votes
1 answer
How to dispatch one argument to multiple function in fp-ts
I have the following code
export const getPostData = (id: string) =>
pipe(
getFullPathFileNameForPosts(`${id}.md`), // IO
chain(getFileContents), // IO
chain(getMatter), // IO>
…

levin.li
- 23
- 4
2
votes
1 answer
What is an fp-ts Predicate?
I'm trying to implement some simple data validation with fp-ts, and came across this codesandboxexample:
import * as E from "fp-ts/lib/Either";
import { getSemigroup, NonEmptyArray } from "fp-ts/lib/NonEmptyArray";
import { sequence } from…

ANimator120
- 2,556
- 1
- 20
- 52
2
votes
2 answers
How to fold two different types? FP-TS
I'm learning FP with FP-TS and I just hit a road block:
I have the following function in my repository:
// this is the repository
export const findBook = (id: string) => TaskEither>
that part is easy and makes sense to…

kibe
- 90
- 1
- 8
- 26
2
votes
1 answer
How to use already defined interface with io-ts library?
I am using @types/fabric package in my application. I want to use predefined interfaces (like ICircleOptions, IRectOptions ..etc.) from fabric types.
How can I use these interfaces with io-ts library for runtime typechecking.
I have defined a type…

Abhishek T.
- 1,133
- 1
- 17
- 33
2
votes
1 answer
How to use the Task monad? (fp-ts)
import * as T from 'fp-ts/lib/Task'
import { pipe, flow } from 'fp-ts/lib/function'
const getHello: T.Task = () => new Promise((resolve) => {
resolve('hello')
})
I understand the purpose of Task and why is it important. The thing is that…

padowbr
- 31
- 1
- 3
2
votes
2 answers
Nested Data Fetching fp-ts pyramid of doom
First jump into the world of functional programming in typescript with the fp-ts library.
I have here a "pyramid of doom" the Egyptians would be proud of, I'm clearly doing something wrong in my approach. What approach should I be taking to solve my…

Robert Field
- 321
- 5
- 16
2
votes
1 answer
fp-ts/typescript avoid nested pipes
How can I avoid nested pipes when using fp-ts in typescript? Do notation? Here's an example of nested pipe I want to avoid
pipe(
userId,
O.fold(
() => setUser('No user found'),
(uId: string) => {
fetchUser(uId).then((response:…

Arun Gopalpuri
- 2,340
- 26
- 27
2
votes
1 answer
How to define mixed array in io-ts?
Using latest io-ts, I would like to model property result of NodeLsStatusResponse to contains objects of type NodeStatus or NodeStatus404 in (t.readonlyArray)
How to define this relationship with io-ts?
export const Connection =…

GibboK
- 71,848
- 143
- 435
- 658
2
votes
0 answers
Converting Task> to ReaderTask with FP-TS
I'm looking for a concise way of converting a Task> to ReaderTask using TypeScript. The following seems to work but I'm wondering if the function is already available in FP-TS.
import { pipe } from 'fp-ts/lib/pipeable';
import {…

cyberixae
- 843
- 5
- 15
2
votes
3 answers
fp-ts and jest: ergonomic tests for Option and Either?
I'm using fp-ts, and I write unit tests with Jest. In many cases, I'm testing nullable results, often represented with Option or Either (typically, array finds). What is the most ergonomic way to make the test fail if the result is none (taking…

Gabriel Theron
- 1,346
- 3
- 20
- 49
2
votes
1 answer
IO consuming with FP-TS
What is the idiomatic fp alternative of forEach part in this code
const ios: IO[] = [...]
ios.forEach(io => io());
?
There are some docs which use sequence_ from Foldable but it is no longer available in fp-ts@2.0.3.
EDIT:
The best I could…

MnZrK
- 1,330
- 11
- 23
2
votes
1 answer
Task, Lift and complex monads in FP-TS
I have the following code:
import { Task, task } from "fp-ts/lib/Task"
import { Either, left, right } from "fp-ts/lib/Either"
import { curry } from "fp-ts/lib/function"
import { liftA2 } from "fp-ts/lib/Apply"
import { Repo } from "./repo"
const…

Ezequiel Lewin
- 73
- 5