Questions tagged [fp-ts]

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

Links

198 questions
0
votes
1 answer

Generically extract a value from typed Record

I am using fp-ts and in this case, Options. Lets say I have an example type: import * as O from 'fp-ts/Option'; type ExampleType = { a: number, b: O.Option, c: O.Option } and a record of these types: type ExampleRecord =…
Lucas Manzke
  • 108
  • 8
0
votes
1 answer

How to extract value type from object and keys in typescript

I am using arg and fp-ts. I want to have a function that returns type based on one of the inputs key value. export const getArg = (args: Result) => (argName: {[K in keyof T]: T[K]}): O.Option => …
Danil
  • 103
  • 7
0
votes
2 answers

How to test TaskEither form fp-ts with jest

I am new to fp-ts. Let's say I have a function (path: string) => TaskEither which reads and parses config, and I want to write a test for that. So far I have: test('Read config', done => { interface Config { fld1: string fld2:…
Danil
  • 103
  • 7
0
votes
1 answer

Using POJOs in fp-ts

I want to do what I think is the simplest thing, map through a plain old Javascript object, using fp-ts constructs. There are a lot of operators I would like to use — map, filterMap, and so on — but they seem to require the Map type (which I assume…
Michael Lorton
  • 43,060
  • 26
  • 103
  • 144
0
votes
1 answer

Why does reducing an Array of Option with ap result in None?

I am trying to do this for learning. But I can't get it to work (big surprise since you're reading this :) ) The algo: Have a mixed list of valid/invalid objects as input Extract the desired property from each object (or null) Transform to a list…
rollingBalls
  • 1,808
  • 1
  • 14
  • 25
0
votes
0 answers

importing hybrid package in react native/typescript/expo

I'm trying to import the library fp-ts-std but my import fails. The readme refers to conditional exports, that is: the library exports 2 versions. More thoroughly explained here. One for cjs in fp-ts-std/dist/cjs One for ES-modules in…
Simon
  • 621
  • 4
  • 21
0
votes
1 answer

fp-ts filterWithIndex "index signatures are incompatible"

Learning typescript via fp-ts leads me to trouble. I'm getting the following error: Type 'Record' is not assignable to type 'Timestamps'. Index signatures are incompatible. Type 'number' is not assignable to type…
Simon
  • 621
  • 4
  • 21
0
votes
1 answer

Struct of these

Given a structure where each property is of type These where E and A are different for each prop. declare const someStruct: { a1: TH.These; a2: TH.These; a3: TH.These; } I'm treating These like this left:…
florian norbert bepunkt
  • 2,099
  • 1
  • 21
  • 32
0
votes
1 answer

fp-ts: Option[] to Option with mapping step

I'm wondering if there is a more concise and efficient way to achieve the following code: import { pipe } from 'fp-ts/function' import * as A from 'fp-ts/Array' import * as E from 'fp-ts/Option' pipe( O.some(['foo', 'bar', 'baz']), //…
james2mid
  • 35
  • 2
  • 5
0
votes
1 answer

Change codec of one property in io-ts Codec.struct

I have some objects where I want to change the Codec of one Property. Fort example I have a struct with a date field. Depending on 3rd system apis sometime the input value comes in form of a timestamp, sometimes in form of an ISO string. Is it…
florian norbert bepunkt
  • 2,099
  • 1
  • 21
  • 32
0
votes
1 answer

Flattening a nested Lazy List that may or not have children with FP-TS or Ramda?

I just learned about lift and applicatives and on my quest to trying to understand these structures I am trying to implement a real use case. I have a List (array) that is lazy, meaning that I can't get the count of items or their children until I…
Ricardo Silva
  • 1,221
  • 9
  • 19
0
votes
1 answer

Replace array element in fp-ts

How would I go about replacing the string cat with dog in the array below? My example below is a mix of standard js and fp-ts, was curious if there was something in the Array module that would solve this. const animals =…
Jonathan Southern
  • 1,121
  • 7
  • 22
0
votes
2 answers

How to fold/reduce a map?

I want to be able to fold/reduce a Map, just like I can with Array and Set. The closest I see is something called getFoldableWithIndex but I don't know how to use it or get it to compile with Typescript. One thing I find annoying is that it requires…
JustinM
  • 913
  • 9
  • 24
0
votes
1 answer

Decoder with mutually exclusive properties

Using the Decoder API, is there a way to define a decoder with mutually exclusive properties? import * as D from 'io-ts/Decoder'; const decoder = pipe( D.struct({ a: D.string }), D.intersect( D.partial({ b: D.string, c:…
Rich Churcher
  • 7,361
  • 3
  • 37
  • 60
0
votes
1 answer

fp-ts: given an array of Option, return an array of the values of the some items so that it is typed as an array of strings

I'm attempting to validate an operation of applying a command to an array representing svg path data using fp-ts. type CommandValidation = (commands: CommandArray, nextCommand: Command) => option.Option; const newCommandValidations:…
J. Barca
  • 538
  • 6
  • 19