Questions tagged [fp-ts]

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

Links

198 questions
1
vote
1 answer

FP-TS: mapping responses

I am using the fp-ts library and I cannot figure out how to implement the following scenario: Let's say I have a service with the request method getBooks(shelf, page) and the response looks like this (the request is paginated): { totalItems:…
1
vote
1 answer

Transform Either[] into Either

As the title says, I want to transform Either[] into Either The rule is, if there is a single left-value (an error), I want to get a left-value with all the errors; otherwise, I want the right answers. This seems like it should be…
Michael Lorton
  • 43,060
  • 26
  • 103
  • 144
1
vote
1 answer

Find the smallest date in a list of dates using a Monod or a Semigroup

I was trying to build a function that folds and array of dates to the smallest date. I am using fp-ts for this, and I want to do it in a functional way. I first tried to build it using Monoids, but there was not an easy way to build a min monoid…
Danielo515
  • 5,996
  • 4
  • 32
  • 66
1
vote
2 answers

How to lookup the value for a key in type Json (fp-ts)?

I can extract a value from a json string in an Option with this code: Code that works import { identity, pipe } from "fp-ts/lib/function"; import * as E from "fp-ts/Either"; import * as O from "fp-ts/lib/Option"; import * as R from…
xav
  • 4,101
  • 5
  • 26
  • 32
1
vote
1 answer

How to map a wrapped value in fp-ts?

I have this code and I was wondering if I can transform the below pipes into just one pipe? const result: TE.TaskEither = pipe( this.ensureFundsExist(), TE.chain((funds) => { return pipe( …
Adam Arold
  • 29,285
  • 22
  • 112
  • 207
1
vote
1 answer

Simplify fp-ts function

I have this function: export const getProducts = makeRequest( /** Your query */ `asasd*[_type == "product"] { _id, title }`, /** Optionally transform the response */ (i) => i, /** Validate exact type */ …
eivindml
  • 2,197
  • 7
  • 36
  • 68
1
vote
2 answers

What problem does the Kleisli arrows solve in fp-ts?

I'm learning functional programming by using fp-ts lib and noticed that some functions end with K, like: chainTaskEitherK chainEitherK fromTaskK Also I read the explanation of What a K suffix means in fp-ts documentation, but unfortunately I can't…
Roman Mahotskyi
  • 4,576
  • 5
  • 35
  • 68
1
vote
1 answer

How to build a correct data flow using Do-notation?

I just started to learn functional programming world by using fp-ts lib. At this moment I can understand basic concept of proposed function by this lib, but I can't understand how to glue them all together in the single data flow. I would like to…
Roman Mahotskyi
  • 4,576
  • 5
  • 35
  • 68
1
vote
4 answers

How to handle "else if" in fp-ts

A lot of times I notice I am struggling how to implement a pretty simple flow chart with multiple if-else conditions. This example looks too verbose and is not really scalable if more conditions are added later on: import * as O from…
Mr.B
  • 67
  • 3
  • 9
1
vote
1 answer

How to perform grouped-by aggregations on array of objects in fp-ts?

I'm trying to analyze data given as an array of nested objects. I want to use fp-ts ecosystem, and I'm trying to figure out how I could combine a grouped-by calculation with any pre-defined function (such as, calculating average, median, mode, sum,…
Emman
  • 3,695
  • 2
  • 20
  • 44
1
vote
1 answer

Cannot fix error Types of parameters 'r' and 'a' are incompatible

I try to replicate this code from this blog, but running into some pretty obscure errors import { option, identity, apply } from 'fp-ts'; import type { Kind, URIS } from 'fp-ts/HKT'; import { pipe } from 'fp-ts/lib/function'; type OrderId =…
Sté
  • 195
  • 11
1
vote
1 answer

Does fp-ts have loop functionality

Does fp-ts have any functionality to do a while loop (stack safe) with timeout. Like tail recursion, Y Combinator or something. I have seen ChainRec, but there aren't really any documentation besides functions signatures. Exact issue I have: I need…
Danil
  • 103
  • 7
1
vote
0 answers

dynamic Optional.fromPath

Can i access nested properties with monocle-ts in a dynamic fashion? The closest i can find directly from the library is the Optional.fromPath, combined with a dynamic path. Based on the example from the documentation for fromPath we can create a…
Simon
  • 621
  • 4
  • 21
1
vote
1 answer

How do I convert this to a Point-free function

import { chain, map, Apply } from "fp-ts/lib/IO"; import { log } from "fp-ts/lib/Console"; import { pipe } from "fp-ts/lib/function"; import * as D from "fp-ts/lib/Date"; import { sequenceT } from "fp-ts/lib/Apply"; import { v4 as uuidv4 } from…
1
vote
3 answers

Ramda pick for fp-ts options / maybe

Using fp-ts. I have an option of an array const arrayofKeys: Option>, and an option of a record const record: Option> I want to pick the Vs of the Record where Ks intersect with the Array and stick the result in an Option. In…
Simon
  • 621
  • 4
  • 21