blob: 0c4bf982ccc87ae9474d415dd76783a857dba213 [file] [log] [blame]
// run
// Copyright 2020 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"log"
"strconv"
)
func FromStrings3[T any](s []string, set func(*T, string)) []T {
results := make([]T, len(s))
for i, v := range s {
set(&results[i], v)
}
return results
}
type Settable int
func (p *Settable) Set(s string) {
i, err := strconv.Atoi(s)
if err != nil {
log.Fatal(err)
}
*p = Settable(i)
}
func main() {
s := FromStrings3[Settable]([]string{"1"},
func(p *Settable, s string) { p.Set(s) })
if len(s) != 1 || s[0] != 1 {
log.Fatalf("got %v, want %v", s, []int{1})
}
}