fp-ts is a library for typed functional programming in TypeScript.
Questions tagged [fp-ts]
198 questions
0
votes
1 answer
io-ts how to use a custom union as type to be checked at run time
I would like to use a custom union, or generally a custom type in io-ts.
I receive an error in this like
T.array(T.type(MyUnion))
Could you please tell me what is the right way to achieve this?
import * as T from 'io-ts';
import * as E from…

Radex
- 7,815
- 23
- 54
- 86
0
votes
2 answers
How can I create an Eq for an object with an optional property?
I am trying to create an Eq for an object with an optional property. So far I have tried the following:
type Thing = { a: string; b?: string };
const eqThing = Eq.struct({
a: S.Eq,
b: S.Eq // Type 'Eq' is not assignable to type…

gburnett
- 755
- 8
- 18
0
votes
1 answer
How to implement lazy altAll method?
I want to use Option instead of switch. I tried Alt.altAll, and it works fine:
function foo(a: number) {
return alt.altAll(O.Alt)(O.none)([
O.fromPredicate(() => a >= 85)('A'),
O.fromPredicate(() => a >= 75)('B'),
…

Mxcpanel
- 95
- 7
0
votes
1 answer
Is there any build-in method in fp-ts to reduce an array of functions each one taking as argument the result of the other and returning a TaskEither?
Suppose we have an array of functions each one taking a number and returning a TaskEither.
let tasks: (n: number) => TE.TaskEither[] = [];
The goal is to provide an initial value and then execute each function in…

PSF
- 26
- 4
0
votes
1 answer
What is the difference between Either and Either
I'm new to fp-ts, I saw some people use Either and others use Either in different articles. I want to know the difference between the two, and how should I choose which one to use? Thanks!

Mxcpanel
- 95
- 7
0
votes
2 answers
Is there a Do/Bind pattern to create an object containing different types in fp-ts?
I’m looking for something like Record.Do with Record.bind so I can do something like this
function getB: (a:A) => B
function getC: (b: B) => C
function getD: (c: C) => D
type Z = {
a: A,
b: B,
c: C,
d: D,
}
const getZ = (a: A): Z => pipe(
…

Manav Chawla
- 61
- 2
- 6
0
votes
1 answer
insertAt using fp-ts to insert element at specific index
Trying to simply insert some element at specific index using insertAt util function from fp-ts but insertAt returns Option | NonEmptyArray which returns object like
const x = insertAt(1, 100)([0, 10]) => { _tag: "someTag", value: [0, 100, 10]…

elzoy
- 5,237
- 11
- 40
- 65
0
votes
1 answer
parser-ts: simple many parser goes into infinite loop
Trying to understand how parsers work in parser-ts, but encountered a pretty unexpected behaviour, a simple P.many parser run on a string just hangs for ever, what am I doing wrong?
const everything = pipe(
Ch.alphanum,
P.alt(() =>…

dark_ruby
- 7,646
- 7
- 32
- 57
0
votes
2 answers
Why do we need something like _tag property on Option type in tp-ts?
I'm looking at Option type in fp-ts library. From its definition, we have an internal property _tag on the Some and None interfaces.
https://github.com/gcanti/fp-ts/blob/master/src/Option.ts
interface None {
readonly _tag: 'None'
}
interface…

Shnd
- 1,846
- 19
- 35
0
votes
0 answers
Create a graph model with TaskEither in fp-ts
I'm playing around fp-ts to understand how does it work and I have a question.
Let's say having a model like this:
export interface Category {
id: number;
categories: Category[];
...more fields
}
So, it's a graph of categories which each one…

Roberto
- 41
- 3
0
votes
1 answer
How to sort arrays in fp-ts?
I want to create a function to sort an array of for example strings.
This seems to outline the way, but as so often, I struggle with understanding the documentation.
So my questions are:
What is Ord doing?
What is contramap doing?
How to then build…

Woww
- 344
- 2
- 10
0
votes
1 answer
Traverse/sequence an Array> into Either, Array> in fp-ts
I have a list of entities where even one failed validation would yield an error. However, I'd still like to iterate the whole list and collect all the errors for further logging.
Traverse/sequence with a default Either's Applicative would yield…

Igor Loskutov
- 2,157
- 2
- 20
- 33
0
votes
1 answer
when use "Either in fp-ts" for front-end develop?
tldr : I want to know when to use "either" except network I/O.
In my understanding, Either is used when distinguishing success from fail.
So I use "Either" when network request that may fail.
there are any case other case to use Either in front-end…

LKB
- 457
- 6
- 16
0
votes
1 answer
can you catch the rxjs filter like catching an either left
I would like to know if it's possible to catch when the condition of the rxjs filter condition isn't true.
this is what I have:
of(1)
.pipe(
map((d) => d + 1),
filter((d) => d === 0),
map((d) => d + 1), // this will go in…

Thibaud
- 1,059
- 4
- 14
- 27
0
votes
1 answer
Dealing With Assertions in Functional Code
While doing functional programming I often end up in situations where I know something that the type system of the language does not know. Consider the following TypeScript example that parses a UUID and shows the embedded fields to the user. The…

cyberixae
- 843
- 5
- 15