Questions tagged [fp-ts]

fp-ts is a library for typed functional programming in TypeScript.

Links

198 questions
1
vote
1 answer

What is the other name for Maybe monad?

I know that in FP there are sometimes multiple terms to say one thing. So when I started to learn fp-ts API (https://github.com/gcanti/fp-ts/blob/master/docs/index.md) I couldn't find Maybe monad. So maybe there is another name for it?
Nurbol Alpysbayev
  • 19,522
  • 3
  • 54
  • 89
0
votes
0 answers

functional typescript: error in pipeline converting postgres database results to a view model (fp-ts)

I am trying to retrieve data from a postgresql database, transform it to a view model array and return the data to the client, ideally as a single object in this case rather than an array. I am getting the following error for the code I have listed…
user1790300
  • 2,143
  • 10
  • 54
  • 123
0
votes
0 answers

Point-Free Function using Typescript fp-ts

I'm learning FP using fp-ts and as an exercise to learn how to use RTE, I'm trying to (re)implement fetch-fp-ts. Here's what I've got so far: import type { Request, Response } from "fetch-fp-ts"; import * as F from "fetch-fp-ts"; import * as E from…
Rad
  • 4,292
  • 8
  • 33
  • 71
0
votes
0 answers

FP-TS: Return Either.DO left (errors) in the same format as right

I've come across certain challenge with Either.DO Here's a working example import * as A from 'fp-ts/Apply' import * as E from 'fp-ts/Either' import { pipe } from 'fp-ts/function' import * as S from 'fp-ts/Semigroup' import * as string from…
v0rs4
  • 106
  • 5
0
votes
1 answer

How to get access to a variable in a ReaderTaskEither from an error handling function using fp-ts?

I have this code where I use ReaderTaskEither: export const AddUserToTeam = ({ userId, teamId }: AddUserToTeamDto) => { return pipe( // Uses ReaderTaskEither Do, bind("deps", () => ask()), bind("tx", ({…
Adam Arold
  • 29,285
  • 22
  • 112
  • 207
0
votes
1 answer

Execute an async call in a pipe function with fp-ts?

I'm using fp-ts to fetch two data sets and then pass that to a single function (or handle errors). This function works, but I have to use .then() or await to get it to work. How can I make this "more functional" by using some native fp-ts functions,…
eivindml
  • 2,197
  • 7
  • 36
  • 68
0
votes
1 answer

fp-ts TaskEither pipeline composed with Either pipelines

I am writing a program/pipeline using fp-ts modules Either and TaskEither where the first step is to perform a TaskEither asynchronous operation that may possibly fail ("fetch document for ID"), and in a pipeline do synchronous processing that may…
qqq
  • 1,360
  • 1
  • 9
  • 24
0
votes
0 answers

fp-ts: What is the inverse operation of A.sequenceT?

The operation A.sequenceT allows to convert a sequence of typed Monads into a Monad of a typed tuple, such as in this Option example: const sequenceO = A.sequenceT(O.Apply); const o1: Option = O.some(1); const o2: Option
Carsten
  • 468
  • 4
  • 16
0
votes
1 answer

React Hook useCallback() with useState var not updating state

I have a react-native app that has boolean values to render certain components but the state is not updating in useCallback export const Foo = (props): => { const value = undefined const [bar, setBar] = useState(false) …
0
votes
1 answer

fp-ts flow/pipe but output is "merged" with input as each function is called

I'm trying to write a library where the input is an Array of functions where the output of each function is merged in with its input and then passed into the next function. Basically similar to compose/flow/pipe, but the input is always a single…
NSjonas
  • 10,693
  • 9
  • 66
  • 92
0
votes
2 answers

How to do a flatMap with an NonEmptyArray in fp-ts way?

I have a class like this: class ValidationError { constructor( public readonly errors: NonEmptyArray, ) {} } And have a NonEmptyArray, but I want to transform it into a single ValidationError with all the errors…
0
votes
1 answer

Get the static type from generic runtime type

Try to get the ApiResponse static TS generic type from the generic runtime type created by io-ts. No information in official documentation Expect type: // runtime type const ApiResponseCodec = (codec: C) => t.type({ code:…
Lin Du
  • 88,126
  • 95
  • 281
  • 483
0
votes
1 answer

If error happens throw error else return the value

Try to send an HTTP request with parameter validation. If the parameter validation fails, throw "parameter invalid" error and stop the following executions. If the code of the API response doesn't equal '0', throw res.message error else return the…
Lin Du
  • 88,126
  • 95
  • 281
  • 483
0
votes
1 answer

fp-ts Split an array into multiple partitions

I'm new to fp-ts, and I was wondering whether there's a utility/pattern for splitting an array into multiple partitions based on another array of indices/keys, such that the regular functions e.g. map() and foldMap() would operate on the partitions…
Adam B.
  • 788
  • 5
  • 14