Skip to content

Commit

Permalink
feat(function-call): add alternative lambda syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
kantord committed Oct 7, 2018
1 parent e94a5ac commit eb84f40
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
11 changes: 5 additions & 6 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ returned.

In any other case, a list of each requested element is returned.


### Functions

#### `join`
Expand Down Expand Up @@ -90,19 +89,19 @@ separator.
Input:

```
["Hello", "World!"] | map \{"word": $}
["Hello", "World!"] | map $ => {"word": $}
```

Output:

```json
[
{ "word": "Hello"},
{ "word": "World!"},
]
[{"word": "Hello"}, {"word": "World!"}]
```

Alternatively, you can also use this syntax: `["Hello", "World!"] | map \ {"word": $}`

### Chaining filters

You can combine two filters by using the pipe syntax, e. q. `.foo | .bar`

The first filter (`.foo`) will receive the input and transform it; the second
Expand Down
15 changes: 15 additions & 0 deletions src/parsers/__tests__/functionCallLambda.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@ describe('functionCallLambda parser', () => {
it('parses map \\"foo"', () => {
expect(parser.parse('map \\"foo"').status).toBe(true)
})
it('parses map \\ "foo"', () => {
expect(parser.parse('map \\ "foo"').status).toBe(true)
})

it('parses map $ => "foo"', () => {
expect(parser.parse('map $ => "foo"').status).toBe(true)
})

it('parses map $ =>"foo"', () => {
expect(parser.parse('map $ =>"foo"').status).toBe(true)
})

it('parses map $=>"foo"', () => {
expect(parser.parse('map $=>"foo"').status).toBe(true)
})

it('returns correct value', () => {
expect(parser.parse('map \\["a", "b"]').value).toEqual({
Expand Down
2 changes: 1 addition & 1 deletion src/parsers/functionCallLambda.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const FunctionCallLambdaParser = Parsimmon.lazy((): mixed => {
return Parsimmon.seq(
IdentifierParser,
Parsimmon.optWhitespace,
Parsimmon.string('\\'),
Parsimmon.alt(Parsimmon.regexp(/\$\s*=>\s*/), Parsimmon.string('\\')),
Parsimmon.optWhitespace,
ProgramParser
).map(
Expand Down

0 comments on commit eb84f40

Please sign in to comment.