Skip to content

The partob example in the tutorial is all written wrong #499

Description

@WZ-AnNi

In Source Code

/**
 * Like partial but for unary functions that accept
 * a single object argument
 */
export const partob = <T, K, PartialArgs extends Partial<T>>(
  fn: (args: T) => K,
  argobj: PartialArgs
) => {
  return (restobj: Omit<T, keyof PartialArgs>): K =>
    fn({
      ...(argobj as Partial<T>),
      ...(restobj as Partial<T>)
    } as T)
}

This means that the function acceptable to thepartob function must have a single object parameter
Example:

import { partob } from "radash";
- const add = (a: number, b: number) => a + b;
- const addA1 = partob(add, { a: 1 });
+ const addButArgsIsObj = (arg: { a: number; b: number }) => arg.a + arg.b;
+ const addButArgsIsObjA1 = partob(addButArgsIsObj, { a: 1 });

But in the tutorial, it is almost all wrong. The former is not the correct way to write the latter.

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions