Questions tagged [fp-ts]

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

Links

198 questions
1
vote
2 answers

Transforming union type into Either type in fp-ts

In typescript, how can I transform a union type A|B into fp-ts's Either? It feels natural and there must be a nice way of doing it.
1
vote
2 answers

TypeScript generic runtime type check

Is it possible for runtime data to specify the type for a runtime type check? Hopefully using io-ts? A switch statement creates more than one place to add new types. Looking up object properties like types[runtime.type] creates compile time type…
steve76
  • 302
  • 2
  • 9
1
vote
0 answers

How to vallidate user with fp-ts on server?

I'm new to functional programming so a lot of things is still unclear for me. I'm trying to write my graphql server with fp-ts and I'm stuck with user authorisation. I'm expecting authorisation like: validate user data -> check is he existed ->…
1
vote
1 answer

Getting the first successful value in an array of TaskEithers

I'm relatively new to functional programming and very new to fp-ts, so I'm having a struggle wrapping my head around the util functions provided. I'm currently trying to figure out how to handle TaskEithers as fallbacks in an array. I have a…
bigpopakap
  • 381
  • 5
  • 13
1
vote
0 answers

Point free style for two functions "combined" (not composed)

I'm doing this in TypeScript, but would be OK with a response in another language with FP abilities. Say I've got const foo = (a:A) => M and const bar = (b:B) => N. I'd like to run these functions "in parallel" (doesn't have to be actual parallel IO…
user1713450
  • 1,307
  • 7
  • 18
1
vote
0 answers

Run list of validation functions over a single input with fp-ts

I am using fp-ts to handle validation in my application. I want to write a function that accepts a list of validators and runs all of them over a single input. These are the types I want to use: import { Either } from "fp-ts/lib/Either"; import {…
Grancalavera
  • 143
  • 1
  • 8
1
vote
2 answers

fp-ts: Filter array based on next element

I am starting with functional programming / fp-ts. I am trying to write a function that, taking a list, retains an element if a condition on the next element is fulfilled. Example: const condition = (i: number) => i % 10 === 0; filterNext(condition,…
Pierre
  • 6,084
  • 5
  • 32
  • 52
1
vote
1 answer

Managing array of monads in fp-ts and Functional Programming

I'm very new to Functional Programming and I'm struggling a lot with running traverse on arrays. When I read this book it seems that I should be able to simply traverse between Monads but I can't wrap my head around this concept with fp-ts. Can…
Amin Paks
  • 276
  • 2
  • 15
1
vote
1 answer

In fp-ts what is the advantage of using Option instead of typescript's optional (question mark)

I am getting started with fp-ts and was wondering what is the advantage of using Option type over typescript's default notion of optional values represented by question mark?
almeynman
  • 7,088
  • 3
  • 23
  • 37
1
vote
2 answers

Convert TaskEither[] to TaskEither

I am still learning and playing with fp-ts and can't figure this out. I have some API calls and I want to collect all the successful responses and all the errors into arrays. So, I tried to use array.sequence: TE.map(schedules => …
Vasileios Pallas
  • 4,801
  • 4
  • 33
  • 50
1
vote
1 answer

How to manage monads in FP and specially in fp-ts

I'm very new to functional programming and specially fp-ts library. My question includes two parts: I'm seeing a pattern of turning Monads from one type to another like from Task to IO or vice versa, how do we manage this, should we stay always on…
Amin Paks
  • 276
  • 2
  • 15
1
vote
1 answer

Map IO to array of Either in fp-ts

Can anyone help me to figure out how to do this in fp-ts? const $ = cheerio.load('some text'); const tests = $('table tr').get() .map(row => $(row).find('a')) .map(link => link.attr('data-test') ? link.attr('data-test') : null) .filter(v => v…
Amin Paks
  • 276
  • 2
  • 15
1
vote
2 answers

How to convert Either> into TaskEither in fp-ts

I have a pipe that return Either> but what I need is TaskEither. How can I convert Either> to TaskEither? Is there any helper any utility function for doing this?
mohsen saremi
  • 685
  • 8
  • 22
1
vote
1 answer

Type modeling with TypeScript and fp-ts and error while using Either

I'm trying to use TypeScript and fp-ts to get my feet wet in modeling domain logic with types and I've come across this problem: import { left, right, Either } from "fp-ts/lib/Either"; type MyType = { id: string, isValid: boolean, } type…
Alerosa
  • 568
  • 1
  • 5
  • 14
1
vote
1 answer

What is the name of the wheel from FP, that I am trying to invent? (see the code)

The desired final typescript code is: transform(input)(transformation1)(transformation2)(... // input is any data, e.g. string or object // transformationX should be a transforming function I've wrote the code below so far, and I feel like I am…
Nurbol Alpysbayev
  • 19,522
  • 3
  • 54
  • 89