<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                [TOC] ## pointed functor - *pointed functor*是實現了`of`方法的 functor(詳情查看第八章) bad ``` // Support // =========================== var fs = require('fs'); // readFile :: String -> IO String var readFile = function(filename) { return new IO(function() { return fs.readFileSync(filename, 'utf-8'); }); }; // print :: String -> IO String var print = function(x) { return new IO(function() { console.log(x); return x; }); } // Example // =========================== // cat :: IO (IO String) var cat = compose(map(print), readFile); cat(".git/config") // IO(IO("[core]\nrepositoryformatversion = 0\n")) ``` 我們得到的是一個`IO`,只不過它陷進了另一個`IO` good ``` var mmo = Maybe.of(Maybe.of("nunchucks")); // Maybe(Maybe("nunchucks")) mmo.join(); // Maybe("nunchucks") var ioio = IO.of(IO.of("pizza")); // IO(IO("pizza")) ioio.join() // IO("pizza") var ttt = Task.of(Task.of(Task.of("sewers"))); // Task(Task(Task("sewers"))); ttt.join() // Task(Task("sewers")) ``` 如果有兩層相同類型的嵌套,那么就可以用`join`把它們壓扁到一塊去 ### 一個 join 一個 functor,只要它定義個了一個`join`方法和一個`of`方法,并遵守一些定律,那么它就是一個 monad ``` Maybe.prototype.join = function() { return this.isNothing() ? Maybe.of(null) : this.__value; } ``` 實例 ``` // log :: a -> IO a var log = function(x) { return new IO(function() { console.log(x); return x; }); } // setStyle :: Selector -> CSSProps -> IO DOM var setStyle = curry(function(sel, props) { return new IO(function() { return jQuery(sel).css(props); }); }); // getItem :: String -> IO String var getItem = function(key) { return new IO(function() { return localStorage.getItem(key); }); }; // applyPreferences :: String -> IO DOM var applyPreferences = compose( join, map(setStyle('#main')), join, map(log), map(JSON.parse), getItem ); applyPreferences('preferences').unsafePerformIO(); // Object {backgroundColor: "green"} // <div style="background-color: 'green'"/> ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看