ts-get icon indicating copy to clipboard operation
ts-get copied to clipboard

Feature request: Add Ramda-compatible composable export

Open icopp opened this issue 6 years ago • 0 comments

This would be similar to the existing export, except with the params flipped, curryable, and defaults split into another export:

import { composableGet as get, composableGetOr as getOr } from 'ts-get';

// these are the same statement
get(obj => obj.a.b.c, inputObject);
get(obj => obj.a.b.c)(inputObject);

// these are the same statement
getOr(defaultValue, obj => obj.a.b.c, inputObject);
getOr(defaultValue, obj => obj.a.b.c)(inputObject);
getOr(defaultValue)(obj => obj.a.b.c, inputObject);
getOr(defaultValue)(obj => obj.a.b.c)(inputObject);

This would allow use with Ramda for things like the following (real simple example):

import { pipe, equals } from 'ramda';
import { composableGet as get } from 'ts-get';

import { getMetadataForIndex } from './whatever-utils';

export function satisfiesCriteria(index: number, type: string): boolean {
    return pipe(
        getMetadataForIndex, // this is passed index
        get(metadata => metadata.a.b.c), // this is passed the output of getMetadataForIndex
        equals(type) // this is passed the output of get
    )(index);
};

icopp avatar Apr 25 '19 22:04 icopp