FGRibreau / FGRibreau/match-when

Support type matching

Open
#15 0 comments 2 reactions 0 assignees View on GitHub
enhancement
Dominant language
JavaScript
Stars
524
Forks
16
PR merge metrics
No merged PRs in 30d

Description

before:

``` js
function replaceInstanceId(elem) {
+ if (_.isPlainObject(elem)) {
+ return _.mapValues(elem, replaceInstanceId);
+ } else if (_.isArray(elem)) {
+ return _.map(elem, replaceInstanceId);
+ } else if (_.isString(elem) && _.includes(elem, 'instance_id')) {
+ return _.template(elem)({instance_id: conf.instance_id});
+ }
+
+ return elem;
+ }
```

after:

``` js
const replaceInstanceId = match({
[when(Object)]:(elem) => _.mapValues(elem, replaceInstanceId),
[when(Array)]:(elem) => _.map(elem, replaceInstanceId),
[when.and(String, /instance_id/)]: (elem) => _.template(elem)({instance_id: conf.instance_id}),
[when()]: _.identity
});
```

Contributor guide

No contributing guide indexed for this repository

Research direction

The issue shows the current replaceInstanceId logic and the intended match({ ... }) syntax using Object, Array, String, when.and, and _.identity. Start by locating the match and when implementation, then check how existing matcher cases are tested. Done means the shown type-based cases work without the manual branching.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.