Skip to content

How can I make ramda's omit in fp-ts? #1818

Answered by ankrut
ammarriq asked this question in Q&A
Discussion options

You must be logged in to vote

Your code does not work because pipe does not support rest parameter for arrays. It is not "passed to a rest". In other words pipe is unfortunately not generic for an arbitrary number of parameters. It supports only max 20 parameters and that's why it is saying "must [...] have a tuple type".

To reflect a loop in functional programming recursion is preferred. In your example you would need to use reduce. For example

import { pipe } from "fp-ts/lib/function";
import { map, reduce } from "fp-ts/Array";
import { deleteAt } from "fp-ts/Record";

// ...

const omit = (arr: string[], obj: object) =>
  pipe(
      arr,
      surround,
      reduce(obj, (reducedObj, f) => f(reducedObj))
  );

Howe…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@ammarriq
Comment options

@ankrut
Comment options

Answer selected by ammarriq
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants