Skip to content

Commit 50b7f30

Browse files
committed
Document pipe operator method calls
1 parent fb15e79 commit 50b7f30

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

docs/New Operators.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,23 @@ producer()
174174
|> print --> 16
175175
```
176176

177+
### Methods Calls
178+
There is specialized syntax for method calls with the pipe operator, too:
179+
```pluto
180+
local producer = || -> 21
181+
182+
local obj = {
183+
function multiply(value)
184+
return value * self.factor
185+
end
186+
}
187+
obj.factor = 2
188+
189+
producer()
190+
|> obj:multiply
191+
|> print --> 42
192+
```
193+
177194
### Anonymous Functions
178195
The righthand side of the pipe operator can also be an anonymous function, allowing for more advanced usage like this:
179196
```pluto

src/theme/pluto.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Prism.languages.pluto = {
55
/\b(?!in\s)(?!\d)(?!return)(?!case)(?!function)(?!local)(?!new)\w+(?=\s*(?:\??\())/, // func()
66
/\b(?!in\s)(?!\d)(?!return)(?!case)(?!function)(?!local)(?!not)\w+(?=\s*(?:\??[{"]))/, // func "", func {}
77
/\b(?!in\s)(?!\d)(?!return)(?!case)(?!function)(?!local)(?!not)\w+(?=\s*(?:\??\[\[))/, // func [[
8-
/(?<=\|>)\s[\w.]+/, // |> func
8+
/(?<=\|>)\s[\w.:]+/, // |> func
99
/\b(function|enum|class)\b/,
1010
/\b(os\.platform|json\.null|json\.withnull|json\.withorder)\b/, // standard library constants
1111
/\b(debug|table|string|number|io|os|coroutine|_VERSION|_PVERSION|_PSOUP)\b/, // standard library + type hints

0 commit comments

Comments
 (0)