Skip to content
This repository has been archived by the owner on May 8, 2021. It is now read-only.

Feature request: Add Ramda-compatible composable export #4

Open
icopp opened this issue Apr 25, 2019 · 0 comments
Open

Feature request: Add Ramda-compatible composable export #4

icopp opened this issue Apr 25, 2019 · 0 comments

Comments

@icopp
Copy link

icopp commented Apr 25, 2019

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);
};
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant