fp-ts is a library for typed functional programming in TypeScript.
Questions tagged [fp-ts]
198 questions
0
votes
1 answer
Is there a way to cast an IO to TaskEither
I was trying to start using fp-ts and I had a really hard time with side-effects.
I wrote a little test program that will read a file, print the file to screen and return an Either.
I used the basic do notation as an example and ended…

nhruo
- 79
- 7
0
votes
1 answer
Merging an Option monad into IOEither?
I was trying to write a localStorage wrapper in fp-ts when I ran into a roadblock. I want to handle null values as well as exceptions thrown by localStorage, so I started with this code:
import * as IOE from "fp-ts/IOEither";
import * as O from…

T. Arafat
- 45
- 1
- 2
- 6
0
votes
1 answer
Reader monad inside RxJs mergeMap
I am using rxjs and want to use Reader monad from fp-ts package as a Dependency Injection solution.
Here is my code:
import { of } from 'rxjs';
import { pipe } from 'fp-ts/function';
import { mergeMap } from 'rxjs/operators';
import * as R from…

mohsen saremi
- 685
- 8
- 22
0
votes
1 answer
Somehow end up with a Promise> instead of TaskEither
I'm not really comfortable with FP-TS just yet (or functional programming in general), so I may be doing some things wrong here.
I have the following function where I'd like to return a TaskEither but I can't seem to get it to…

Matthijn
- 3,126
- 9
- 46
- 69
0
votes
0 answers
Cannot read property 'some' of undefined
I am trying to use https://gcanti.github.io/fp-ts/modules/Option.ts.html as follows:
import O, {Option} from "fp-ts/Option";
....
useEffect(() => {
if (error) {
handleResultCategories(O.none);
return;
}
…

softshipper
- 32,463
- 51
- 192
- 400
0
votes
3 answers
The proper fp-ts way to convert array into object
I'm new to functional programming but wanna learn best practices.
What is the proper fp-ts way to convert array into object?
(items: Item[], keyGetter: (i: Item) => Key) => Record
I use my own not fp-ts implementation so far:
function…

Dmitrii Bykov
- 55
- 12
0
votes
1 answer
io-ts : use TypeOf with DateFromISOString
trying to validate and decode api response:
const Foo = t.type({
id: t.number,
date: DateFromISOString,
});
type FooType = t.TypeOf;
const jsonFoo: FooType = {"id": 1, date: "2021-02-05T11:13:22.520Z"};
const resultFoo…

Anton
- 1,898
- 3
- 18
- 27
0
votes
1 answer
Typescript : match function input type to output type in Array.reduce function
I run into a problem when trying to generate an object through Array.reduce function. This code will work without any issues in javascript. However in typescript I'm not able to match types from the reduce function and it throws the Error shown…

Arvind Kumar
- 35
- 5
0
votes
0 answers
Partition list of task eithers on left/right
Say I have three entities a parent entity, representing ingestion of an array of arrays over a third party API, a Child Entity representing the parsing and processing of one such array members, and errors representing the failure to process…

Abraham P
- 15,029
- 13
- 58
- 126
0
votes
2 answers
Generate a predicate out of two predicates (job for monoid, fold?)
I have two predicates
interface Foo {}
interface Bar {}
declare const isFoo: (a:unknown):a is Foo
declare const isBar: (a:unknown):a is Bar
What is the functional way to combine two predicates to create a new predicate (for simplicity, let's assume…

user1713450
- 1,307
- 7
- 18
0
votes
1 answer
Represent Task[Either] and IO[Either] as a single monad that includes tryCatch?
Is there a way to represent IOEither and TaskEither as a single Monad that will also include the tryCatch?
I currently will consume an API over HTTP, so it makes sense to use TaskEither, but anticipate that this code will migrate "closer to home"…

user1713450
- 1,307
- 7
- 18
0
votes
2 answers
Remove Options from array of items in fp-ts
Say I have the following types:
type ValidatedInput = Readonly<{
id: string
}>
type GetStructures = (id: string) => TaskEither>
type GetOtherStructures = (ids: ReadonlyArray) =>…

Abraham P
- 15,029
- 13
- 58
- 126
0
votes
1 answer
Field-name/ Key validation for io-ts?
how do I ensure that the incoming JSON key is valid? I use t.decode, and it didn't throw an error.
const UserRequired = t.type({
firstName : t.string,
lastName : t.string,
})
const UserOptional = t.partial({
image :…

darren z
- 3,051
- 3
- 13
- 28
0
votes
1 answer
Type predictions work only within pipe function
I'm using monocle-ts (https://github.com/gcanti/monocle-ts) library in my project.
I have the following code
import {id, prop} from 'monocle-ts/lib/Lens'
import {pipe} from 'fp-ts/function'
type State = {a: string, b: string}
const stateLens =…

dps
- 764
- 3
- 7
- 16
0
votes
1 answer
How to go from ReaderEither[] to ReaderEither in fp-ts?
In fp-ts, how do I go from ReaderEither[] to ReaderEither? Essentially I want to convert an array of ReaderEither instances to a single ReaderEither instance.
I've tried searching for the answer, but haven't had much luck. I'm…

Ryan Helmoski
- 359
- 2
- 7