Leviathann
V2EX  ›  问与答

英语里函数的 identity 是啥? Java stream api 的 reduce 文档看不懂

  •  
  •   Leviathann · Aug 9, 2021 · 1180 views
    This topic created in 1767 days ago, the information mentioned may be changed or developed.
    Performs a reduction on the elements of this stream, using the provided identity, accumulation and combining functions. This is equivalent to:

    U result = identity;
    for (T element : this stream)
    result = accumulator.apply(result, element)
    return result;

    but is not constrained to execute sequentially.
    The identity value must be an identity for the combiner function. This means that for all u, combiner(identity, u) is equal to u.

    搜了下大概知道这个 combiner 是并行流合并子流 reduce 的结果用的,但是那个 combiner(identity, u) is equal to u.是啥意思
    2 replies    2021-08-09 12:17:10 +08:00
    sosilver
        1
    sosilver  
       Aug 9, 2021 via Android
    wiki/Identity_element
    Leviathann
        2
    Leviathann  
    OP
       Aug 9, 2021 via iPhone
    @sosilver 原来如此,吃了数学的亏
    我一直以为物理数学里的 单位 都是 unit 。。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   961 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 21:48 · PVG 05:48 · LAX 14:48 · JFK 17:48
    ♥ Do have faith in what you're doing.