dogfootman.com

  • 홈
  • 태그
  • 방명록

Filter 1

[Go] 제네릭 사용 예 (Example of using generics)

개요go 1.18에서 추가 된 제네릭의 사용 예   1. 함수에서의 사용package mainimport "fmt"func Filter[T any](list []T, predicate func(T) bool) []T { var result []T for _, v := range list { if predicate(v) { result = append(result, v) } } return result}func main() { // 짝수만 필터 nums := []int{1, 2, 3, 4, 5, 6} evens := Filter(nums, func(n int) bool { return n%2 == 0 }) fmt.Println(evens) // [2 4 6] // 길이가 5가 넘는 문자열만 필터..

[Go] 2024.06.23
이전
1
다음
더보기
  • View All Categories (13)
    • [Unity] (3)
      • [Unity 2D] (3)
    • [Go] (9)
    • [ETC] (1)

Tag

gob, Camera, test, deep copy, go, Golang, mouse position, API, cycle not allowed, Slice, benchmark, Unity 2D, Interface, 고랭, Unity, struct, scroll wheel, Performance, Dependency, pre-request script,

최근글과 인기글

  • 최근글
  • 인기글

방문자수Total

  • Today :
  • Yesterday :

Copyright © Kakao Corp. All rights reserved.

티스토리툴바