github.com/qioalice/ekago/v3@v3.3.2-0.20221202205325-5c262d586ee4/ekaext/if.go (about)

     1  // Copyright © 2022. All rights reserved.
     2  // Author: Ilya Stroy.
     3  // Contacts: iyuryevich@pm.me, https://github.com/qioalice
     4  // License: https://opensource.org/licenses/MIT
     5  
     6  package ekaext
     7  
     8  func If[T any](cond bool, vThen, vElse T) T {
     9  	if cond {
    10  		return vThen
    11  	}
    12  	return vElse
    13  }
    14  
    15  func ZeroIf[T comparable](v T, cond bool) T {
    16  	return If(cond, *(new(T)), v)
    17  }