<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>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                /\* ?\*?@Author:?禍靈 ?\*?@Date:?2021-04-04?12:19:14 ?\*?@LastEditTime:?2021-04-16?13:24:50 ?\*?@LastEditors:?禍靈 ?\*?@Description:?函子 ?\*?@FilePath:?\\UC-font\\components\\uct\\libs\\lodash\\functor.js ?\*/ /\*\* ?\*?函子是一個特殊的容器,通過一個普通的對象來實現,該對象具有map方法,map方法可以運行一個函數對值進行處理(變形關系) ?\*?let?r?=?Container.of(5).map(x?=>?x?+?1).map(x?=>?x?\*?x)//36 ?\*?副作用?單傳入null時可能會變得不純 ?\*?@description:?函子 ?\*?@param{\*} ?\*?@return{\*} ?\*/ classContainer?{ staticof(value)?{ returnnewContainer(value); ??} constructor(value)?{ this.\_value?=?value; ??} map(fn)?{ returnContainer.of(fn(this.\_value)); ??} } /\*\* ?\*?我們在編程的過程中可能會遇到很多錯誤,需要對這些錯誤做對應的處理 ?\*?Maybe函子的作用就是可以對外部的控制情況做處理(控制副作用在允許的范圍) ?\*?let?r?=?Maybe.of(undefined).map(x?=>?x.toUpperCase())//null ?\*?可以處理空值,但不知道哪里出了問題 ?\*?@description:?Maybe函子 ?\*?@param{\*} ?\*?@return{\*} ?\*/ classMaybe?{ staticof(value)?{ returnnewMaybe(value); ??} constructor(value)?{ this.\_value?=?value; ??} map(fn)?{ returnthis.isNothing()???Maybe.of(this.\_value)?:?Maybe.of(fn(this.\_value)); ??} isNothing()?{ return?\[null,?undefined\].includes(this.\_value); ??} } /\*\* ?\*?Either類似if...else...的處理 ?\*?異常會讓函數變的不純,Either函子可以用來做異常處理 ?\*?可以處理異常并顯示哪里出了問題 ?\*?let?r?=?Either.of('{"name":?"zs"}').map(x?=>?JSON.parse(x))//error:?Unexpected?token?o?in?JSON?at?position?1 ?\*?@description:?Either函子 ?\*?@param{\*} ?\*?@return{\*} ?\*/ classEither?{ staticof(value)?{ returnnewEither(value); ??} constructor(value)?{ this.\_value?=?value; ??} map(fn)?{ try?{ returnEither.of(fn(this.\_value)); ????}?catch?(e)?{ console.log(`error:?${e.message}`); ????} ??} } /\*\* ?\*?IO函子中的\_value是一個函數,這里把函數作為值來處理 ?\*?IO函子可以把不純的動作存儲到\_value中,延遲執行這個不純的操作(惰性執行),包裝當前的純的操作 ?\*?把不純的操作交給調用者來處理 ?\*?let?r?=?IO.of(process).map(p?=>?p.execPath); ?\*?console.log(r.\_value());//E:\\node\\node.exe ?\* ?\*?存在問題:使用函數組合時需要多次調用.\_value() ?\*?const?fs?=?require('fs') ?\*?let?readFile?=?(fileName)?=>?new?IO(()?=>?fs.readFileSync(fileName,?'utf-8')) ?\*?let?print?=?(x)?=>?new?IOMonad(()?=>?x) ?\*?let?cat?=?compose(readFile,?print) ?\*?let?r?=?cat('D:\\\\UCToo/UC-font/components/uct/libs/lodash/curry.js').\_value().\_value() ?\* ?\*?@description:?IO函子 ?\*?@param{\*} ?\*?@return{\*} ?\*/ constcompose?=?require("./compose.js"); classIO?{ staticof(value)?{ returnnewIO(()?\=>value); ??} constructor(fn)?{ this.\_value?=?fn; ??} map(fn)?{ returnnewIO(compose(this.\_value,?fn)); ??} } /\*\*?Monad函子是可以變扁的Pointed函子,IO(IO(x)) ?\*?一個函子如果具有join和flatMap兩個方法并遵守一些定律就是一個Monad函子 ?\*?const?fs?=?require('fs') ?\*?let?readFile?=?(fileName)?=>?new?IOMonad(()?=>?fs.readFileSync(fileName,?'utf-8')) ?\*?let?print?=?(x)?=>?new?IOMonad(()?=>?x) ?\*?let?r?=?readFile('D:\\\\UCToo/UC-font/components/uct/libs/lodash/curry.js').flatMap(print).\_value() ?\*?@description:?Monad函子 ?\*?@param{\*} ?\*?@return{\*} ?\*/ classIOMonad?{ staticof(value)?{ returnnewIOMonad(()?\=>value); ??} constructor(fn)?{ this.\_value?=?fn; ??} map(fn)?{ returnnewIOMonad(compose(this.\_value,?fn)); ??} join()?{ returnthis.\_value(); ??} flatMap(fn)?{ returnthis.map(fn).join(); ??} } module.exports?=?{ Container, Maybe, Either, IO, IOMonad, };
                  <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>

                              哎呀哎呀视频在线观看