zoukankan      html  css  js  c++  java
  • [Functional Programming] Function modelling -- 4. Reader Monda example

    const Reader = run => ({
      run,
      map: f => Reader(x => f(run(x))),
      chain: f => Reader(x => f(run(x)).run(x)),
      concat(o) {
        return Reader(x => run(x).concat(o.run(x)));
      }
    });
    Reader.of = x => Reader(() => x);
    Reader.ask = Reader(x => x);
    
    const prefix = s => m => `${s}${m}`;
    const prefixHttps = prefix("https://");
    const prefixHttp = prefix("http://");
    
    const res = Reader.of("localhost")
      .chain(host =>
        Reader.ask.map(config =>
          config.https ? prefixHttps(host) : prefixHttp(host)
        )
      )
      .chain(domain =>
        Reader.ask.map(config => `${domain.concat(":").concat(config.port)}`)
      )
      .run({ port: 3000, https: true });
    
    console.log(res); // https://localhost:3000
  • 相关阅读:
    MySQL多表查询回顾
    本地SQL查询
    QBC查询
    HQL查询
    Hibernate多对多操作
    Hibernate一对多操作
    表与表之间关系回顾
    x$bh视图
    dba 和 rdba 转载
    What you can talk
  • 原文地址:https://www.cnblogs.com/Answer1215/p/12490382.html
Copyright © 2011-2022 走看看