代码之家  ›  专栏  ›  技术社区  ›  Rob Young

本例中的|>运算符是什么

  •  0
  • Rob Young  · 技术社区  · 7 年前

    这是什么意思 |>

    open Framework
    open Template
    
    let () =
      create_server ()
      |> get "/" (fun req -> h1 ["This is the index page."] |> respond)
      |> get "/:name" (fun req ->
          Printf.sprintf "Hello, %s!" (param req "name") |> respond)
      |> listen 1337
    

    示例取自github repo https://github.com/jdan/ocaml-web-framework

    1 回复  |  直到 7 年前
        1
  •  2
  •   Jeffrey Scofield    7 年前

    接线员 |>

    换句话说, x |> f f x

    let f_parenthesized x = int_of_float (abs_float (sin x))
    
    let f_pipelined x = x |> sin |> abs_float |> int_of_float
    

    (这个函数不是很有用,只是一个例子。)

    推荐文章