fp-ts is a library for typed functional programming in TypeScript.
Questions tagged [fp-ts]
198 questions
4
votes
1 answer
fp-ts Using async function in middle of pipe
I have 3 functions, f1, f2, f3.
f1 and f3 are sync and return Option but f2 is an async function return Promise

mohsen saremi
- 685
- 8
- 22
3
votes
1 answer
Convert type `(env) => (args) => TaskEither` to ReaderTaskEither
In my SPA, I have a function that needs to:
Create an object (e.g. a "tag" for a user)
Post it to our API
type UserId = string;
type User = {id: UserId};
type TagType = "NEED_HELP" | "NEED_STORAGE"
type Tag = {
id: string;
type: TagType;
…

xav
- 4,101
- 5
- 26
- 32
3
votes
2 answers
Is there a pointfree way to do O.alt?
Given a value, I'd like to pass it through two functions each which would return an Option. I'd like to use the first Some which is returned.
To do this, I currently use O.alt like so:
Slightly contrived example:
import { constFalse, pipe } from…

I Stevenson
- 854
- 1
- 7
- 24
3
votes
2 answers
What is the difference between Option and OptionT?
There are two modules in fp-ts:
Option
OptionT
As the Code Conventions chapter says
However usually it means Transformer like in “monad transformers” (e.g. OptionT, EitherT, ReaderT, StateT)
So what is a Transformer? And how do I know what…

Roman Mahotskyi
- 4,576
- 5
- 35
- 68
3
votes
1 answer
In fp-ts, how to compose 2 (or more) Ord instances
Say I have a list of strings and I want to sort them first by string length and then alphabetically (so strings within the list with the same length are sorted alphabetically).
I already have ordString which can be used to sort alphabetically. I can…

harryg
- 23,311
- 45
- 125
- 198
3
votes
1 answer
Async iterators with fp-ts and mongo db
With mongodb in node we can use async iterators. Basic example:
const documents: Record[] = [];
let cursor = db.collection('randomcollection').find();
for await (let doc of cursor) {
documents.push(document);
}
How does async…

florian norbert bepunkt
- 2,099
- 1
- 21
- 32
3
votes
1 answer
FP-TS Equivalent of Lodash or Ramda `cond`?
Trying to figure out how to model multiple cases with fp-ts. Unsure whether my mental model of this operation should be different in fp-ts, whether I can't find the right function to use, or such a function doesn't exist.
For reference,…

Adam
- 2,873
- 3
- 18
- 17
3
votes
1 answer
How to generate a list using monoid concat?
I have been doing functional programming for quite some time now, but I am new to monoids and other pure abstractions. I am wondering if there is a way to generate a list of values by using concat function defined for a monoid?
For example, with 0…

tht
- 31
- 2
3
votes
1 answer
fp-ts - pipe is deprecated
I'm using "fp-ts": "^2.10.5" in my typescript/react project and I'm getting a warning that "pipe" has been deprecated. The code below comes from this tutorial on using fp-ts for error handling and validation:
import { Either, left, right } from…

ANimator120
- 2,556
- 1
- 20
- 52
3
votes
1 answer
OO to functional — learning from everyday problem
I am just about to learn functional programming using fp-ts and I am just asking myself what would be the proper functional way to »convert« such a thing to the functional paradigm:
//OOP:
interface Item {
name: string;
}
class X {
private…

philipp
- 15,947
- 15
- 61
- 106
3
votes
1 answer
Merging typed structs with FP-TS
When using FP-TS I often end up with structs being inside a Task or an IO. I managed to solve the problem by writing a merge function and separate lift functions that make it work with Task or IO. See the included code example for a more detailed…

cyberixae
- 843
- 5
- 15
3
votes
1 answer
Get an Optional, Generic, value from an Object
Say I have the following four objects:
const foo1: Readonly<{foo: number, bar: ?string}> = {
foo: 123
}
const foo1: Readonly<{foo: number, bar: ?string}> = {
foo: 123,
bar: '1123'
}
const bar1: Readonly<{foo2: number, bar2: ?string}> =…

Abraham P
- 15,029
- 13
- 58
- 126
3
votes
2 answers
How can I avoid the pyramid of doom with chain in fp-ts?
I frequently come up against this situation, where I need to complete several sequential operations. If each operation exclusively used data from the previous step, then I could happily do something like pipe(startingData, TE.chain(op1),…

cjol
- 1,485
- 11
- 26
3
votes
1 answer
Typescript: How to kleisli compose (monadic compose) Promise monad using fp-ts
How can I compose two kleisli arrows(functions) f:A -> Promise B and g: B -> Promise C into h:A -> Promise C using fp-ts?
I’m familiar with Haskell so I would ask in this way: What’s the equivalent of >=>(fish operator)?

Ingun전인건
- 672
- 7
- 12
3
votes
1 answer
Using TaskEither with fetch API in fp-ts
I want to wrap Fetch API in fp-ts in some manner:
create request
check status
if status is ok - return json
import * as TE from 'fp-ts/lib/TaskEither';
import * as E from 'fp-ts/lib/Either';
import { flow } from 'fp-ts/lib/function';
import { pipe…

Arseniy Prosvirnin
- 107
- 9