dogfootman.com

  • 홈
  • 태그
  • 방명록

Interface 2

[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

[Go] import cycle not allowed - 해결 방안1: interface를 활용한 해결 방안

개요이전 import cycle not allowed 에러를 인터페이스를 활용해 해결https://dogfootman.com/9 [Go] import cycle not allowed - 예제개요import cycle not allowed가 발생하는 경우+---------------------+ +----------------------+| user 패키지 | | board 패키지 || | | || +-----------------+ | | +------------------+ || | User Struct | | | | Post Struct | || +-----------------+ |dogfootman.com    1. 프로젝트 구조/dependency2│├── main.go├── user│ └─..

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

Tag

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

최근글과 인기글

  • 최근글
  • 인기글

방문자수Total

  • Today :
  • Yesterday :

Copyright © Kakao Corp. All rights reserved.

티스토리툴바