1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Ramdaで再帰呼び出しができない

Last updated at Posted at 2018-12-25

備忘録

参考
javascript - Pointfree recursion in JS with ramda - Stack Overflow

Ramdaを使っているときに再起呼び出しができなくて困った.

上の記事の例を借用します.

こんなとき

const removeNulls = R.when(R.is(Object),
                           R.pipe(R.reject(R.isNil),
                                  R.map(removeNulls)));

このように書くと,

ReferenceError: can't access lexical declaration `removeNulls' before initialization

解決策

アロー関数を使えとのこと

const removeNulls = R.when(R.is(Object),
                           R.pipe(R.reject(R.isNil),
                                  R.map(a => removeNulls(a))));

自分も,なぜエラーが出るのか,なぜアロー関数を使えば解決するのかがわかっていません.

どなたか教えていただけると嬉しいです.

1
1
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?