fp-ts is a library for typed functional programming in TypeScript.
Questions tagged [fp-ts]
198 questions
0
votes
3 answers
Add Two Values Wrapped inside Option Monad
If I have two Option monads containing numbers, how can I add them together whilst not exiting the monad?
import { fromNullable, pipe, chain, map } from 'fp-ts/lib/Option'
let c1 = fromNullable(10)
let c2 = fromNullable(20)
// This is where I'm…

Damien Sawyer
- 5,323
- 3
- 44
- 56
0
votes
1 answer
fp-ts: Filter out certain left values, and error on right
I'd like to ignore certain errors using fp-ts (if they happen, it means everything went well, i.e. missing account during signup process).
I have the following code:
export const handleSignup = async (server: FastifyInstance): Promise => {
…

Alexander Mattoni
- 455
- 8
- 19
0
votes
0 answers
Point free composition of two functions when second takes return val of first AND ALSO the parameters of the first function
Say I'm writing a function that will make an HTTP call to fetch data. I've broken down the API call into smaller functions that I compose:
const buildPayload = (inputs:Inputs) => reader.of({...inputs, some:'bar'}) // (inputs:Inputs) =>…

user1713450
- 1,307
- 7
- 18
0
votes
1 answer
fp-ts call async function inside mapLeft
I am new in fp-ts so please help me resolve my problem:
I need to log the same error multiple times on different levels using asynchronous function. Here is my example code:
const myProgram = pipe(
tryCatch(() => someAsyncFunc(), toError),
…

embe
- 43
- 1
- 1
- 3
0
votes
1 answer
Interdependent operations with functional programming in TypeScript
I'm working on an application written in functional TypeScript using fp-ts and io-ts. I need to retrieve a set of JSON configuration files. Some of these JSON files contain information necessary for retrieving some of the other JSON files. I'm…

cyberixae
- 843
- 5
- 15
0
votes
1 answer
Remove duplicates in array of Either with fp-ts
What's the best way to remove duplicates of an array of Either in Functional Programming using fp-ts?
This is my attemp:
import { either as E, pipeable as P } from "fp-ts";
import { flow } from "fp-ts/lib/function";
interface IItem {
type:…

Amin Paks
- 276
- 2
- 15
0
votes
1 answer
Managing errors in Functional Programming and fp-ts
I'm very new to Functional Programming and specially fp-ts.
What I'm struggling recently is playing with arrays and chaining them into different Monads and at the same time preserving some details related to each step.
Let's say we have a program…

Amin Paks
- 276
- 2
- 15
0
votes
1 answer
Why does it type check?
This one doesn't make sense to me:
import axios from 'axios'
import * as TE from 'fp-ts/lib/TaskEither'
export const getIntent = (sessionId: string, input: string) => process.env.INTENT_URL
? TE.tryCatch(
() =>…

stevemao
- 1,423
- 1
- 16
- 29
0
votes
1 answer
fp-ts pipeline with Option and chain not working
I have this sample code:
import {none, some, chain} from 'fp-ts/lib/Option';
import {pipe} from 'fp-ts/lib/pipeable';
const f1 = (input: string) => {
return some(input + " f1")
};
const f2 = (input: string) => {
return some(input +…

mohsen saremi
- 685
- 8
- 22
0
votes
2 answers
Type error with Either in TypeScript/fp-ts
I'm using fp-ts and I have a function that returns either an HttpError object or a string:
async getPreferencesForUserId(userId: string): Promise> {
const preferences = await…

Jim Wharton
- 1,375
- 3
- 18
- 41
0
votes
0 answers
How to switch from one TaskEither to another depending on condition
I'm a freshman in fp-ts, trying to understand how to compose together some things.
So, I have for example TaskEither, which are doing fetch and based on the result from a fetch I want to run another fetch or jump to next step, currently, I've done…

Dmytro Filipenko
- 861
- 1
- 9
- 25
0
votes
2 answers
How to combine the left sides of Either objects in fp-ts?
I have two validation functions for different values that return Either. I'd like to throw an exception if one of them has a left value and do nothing if both are right. I've never used fp-ts before and can't figure out how to properly combine left…

chiborg
- 26,978
- 14
- 97
- 115
0
votes
1 answer
Compositional function that executes each function until "truthy" value is returned
I am looking for a way to chain functions together similar to overSome or flow within lodash.
This is the comparable function written out.
const e = async ({planGroups, uuid, name, user, organization}) => {
const a = this.getPlanGroupByUuid({…

ThomasReggi
- 55,053
- 85
- 237
- 424
0
votes
2 answers
nodejs createReadStream in functional programming
I would like to have your feedback on the usage of TaskEither using fp-ts or another functional programming library for learning purposes:
I am using a Promise when dealing with a nodejs stream, is it a good solution to use a Promise in this way?…

GibboK
- 71,848
- 143
- 435
- 658
0
votes
2 answers
typescript function overriding with higher order functions
I'm confused by this code:
/**
* Lift a function of one argument to a function which accepts and returns values wrapped with the type constructor `F`
*/
export function lift(
F: Functor3
): (f: (a: A) => B) =>

dagda1
- 26,856
- 59
- 237
- 450