# Pipe expression

**URL:** <https://es.discourse.group/t/pipe-expression/133>\
**Category:** 💡 Ideas\
**Tags:** proposal\
**Created:** [November 18, 2019, 3:51pm UTC](https://es.discourse.group/t/pipe-expression/133 "2019-11-18T15:51:55Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![JSMonk](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/jsmonk/32/1851_2.png) [@JSMonk](https://es.discourse.group/u/JSMonk)\
**Post date:** [November 18, 2019, 3:51pm UTC](https://es.discourse.group/t/pipe-expression/133/1 "2019-11-18T15:51:55Z")

</div>

## Description

When we need to destruct array or object and change value then we need make something like this

```javascript
let { first = "data", second } = getSomeObject();
first = computeFirst(first);

// Or create temporary useless variable

const obj = getSomeObject();
const second = obj.second;
const first = computeFirst("first" in obj ? obj.first : "data");

```

I propose operator which will give ability to us to apply some function to property inside destruction-syntax without mutable or temporary variables

```javascript
const { first | computeFirst = "data", second } = getSomeObject();

```

I think that syntax should be discussed, but it seems lie pipe-symbol is well-known operator in bash and in AngularJS/Vue community.

### Alternative variants

Swap function and argument:

```javascript
const { computeFirst | first = "data", second } = getSomeObject();

```

Use $ as separator:

```javascript
const { computeFirst $ first = "data", second } = getSomeObject();

```

Use -\> or \<- as separator:

```javascript
const { computeFirst -> first = "data", second } = getSomeObject();
// OR
const { first <- computeFirst = "data", second } = getSomeObject();

```

## Usage

Function arguments conversion:

```javascript
function getUserResult({ score | BigInt }) { ... }

```

Node.js environment variables:

```javascript
const splitted = a => a.split(",").map(a => a.trim());

const {
  REPOSITORIES | splitted,
  BRANCH = "master",
  COMMITS | splitted
} = process.env;

```

SQL result to JavaScript:

```javascript
const { createdAt | Date } = getUser(id);

```
