Code Monkey home page Code Monkey logo

hatena-textbook's Issues

for式のfilterに関する記述

https://github.com/hatena/Hatena-Textbook/blob/71680f6d034f8a904e075adecf16faff79ffc653/foundation-of-programming-scala.md#ガードつきのfor

filter メソッドが実装されてるとifでfilterできる

という箇所、withFilterについて書いてない。そもそもテキストのScalaのversionの指定がない(?)ので、どう修正すべきかは、どのScalaのversionをサポートするのか?によるが

  • 古いversionもケアするなら、filterとwithFilter両方に関して(歴史的なこと含め)説明をかく
  • 最新versionのScalaだけでいいなら、上記のfilterの記述をwithFilterに単に置き換えるべき

はてなjs教科書 promiseのコードの問題

WHY?

https://github.com/hatena/Hatena-Textbook-JavaScript/blob/master/async/promise.md

上のリンクでは、次のようなpromiseコードが書いています。

let db;
MongoClient.connect('mongodb://localhost:27017/rssDataBase')
    .then((_db) => {
        db = _db;
        return fs.readFile('./feed.xml', 'utf8');
    })
    .then(rssString => parseString(rssString))
    .then((result) => {
        const items = result.rss.channel[0].item;
        return Promise.all(items.map(item => request(item.link[0])));
    })
    .then((responses) => {
        return responses.map((res) => {
            return {
                url  : res.request.href,
                body : res.body,
            };
        });
    })
    .then((data) => {
        return db.collection('entries').insertMany(data);
    })
    .then(() => {
        db.close();
    });

ここで、fs.readFile('./feed.xml', 'utf8')をreturnしていますが、これは、「https://nodejs.org/api/fs.html#fs_fs_readfile_path_options_callback」 の仕様によると、callback関数を第3引数としてもらっていますし、promiseを使ってラップされてないので、実装に混同する余地があり、コードを修正する必要があると思います。

parseStringという関数も同様です。

HOW?

プロミスでラップした正確なコードを書く

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.