Leviathann
V2EX  ›  问与答

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

  •  
  •   Leviathann · Aug 9, 2021 · 1171 views
    This topic created in 1762 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   ·   2923 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 06:54 · PVG 14:54 · LAX 23:54 · JFK 02:54
    ♥ Do have faith in what you're doing.