github.com/grailbio/bigslice@v0.0.0-20230519005545-30c4c12152ad/example/max.go (about)

     1  // Copyright 2020 GRAIL, Inc. All rights reserved.
     2  // Use of this source code is governed by the Apache 2.0
     3  // license that can be found in the LICENSE file.
     4  
     5  package example
     6  
     7  import (
     8  	"github.com/grailbio/bigslice"
     9  )
    10  
    11  // IntMax computes the maximum integer (by key) of slice, where slice has type
    12  // Slice<K, int>. We will use this trivial slice to illustrate testing
    13  // facilities. See max_test.go.
    14  func IntMax(slice bigslice.Slice) bigslice.Slice {
    15  	return bigslice.Reduce(slice, func(a, b int) int {
    16  		if a < b {
    17  			return b
    18  		}
    19  		return a
    20  	})
    21  }