Purus Education
EN
Lesson 11

パイプラインと Null 合体

Lesson 11 — パイプラインと Null 合体

English

構文

pipe は左の値を右の関数に渡します。データが左から右へ流れます:
5 pipe double                  -- double(5)
5 pipe double pipe increment   -- increment(double(5))
data pipe transform[extra]     -- transform(data, extra)
coal は左辺が null / undefined のときだけ右辺を返します(JS の ??)。or と違い、0false"" はそのまま残ります:
config.port coal 3000          -- config.port ?? 3000
0 coal 99                      -- 0   (残る!)
0 or 99                        -- 99  (or は falsy をすべて捨てる)

課題

1. 5doubleincrement の順に pipe で流して result11 にする。

2. coal を使って、config-portnull のとき port3000 になるようにする。

確認

npm test 11

参考

Loading editor...
Ctrl+Enterで実行