Source file test/typeparam/mapimp.dir/a.go

     1  // Copyright 2021 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package a
     6  
     7  // Map calls the function f on every element of the slice s,
     8  // returning a new slice of the results.
     9  func Mapper[F, T any](s []F, f func(F) T) []T {
    10  	r := make([]T, len(s))
    11  	for i, v := range s {
    12  		r[i] = f(v)
    13  	}
    14  	return r
    15  }
    16  

View as plain text