# Interfaces 101 : Implementing Generics with Interfaces Ep. 1

- Published: January 31, 2023
- Author: Ardan Labs
- URL: https://www.ardanlabs.com/blog/2023/01/interfaces-101-implementing-generics-with-interfaces.html

### Introduction

Go interfaces are beneficial to Go developers because they:

* Allow interfaces to separate mechanism from behavior.
* Increase flexibility of function parameters.
* Enable mocking of function parameters.

With the addition of generics in Go 1.18, interfaces can be used to constrain the types of values a generic function will accept. To dive deeper into Go interfaces, we invite you to join Miki in his latest series dedicated to Go interfaces.

![](../../../images/blog/interfaces-01.jpg?v=1)

In this video, Miki has two functions that perform the same operation, but return different types. To remove the duplicate code, Miki will replace the two functions with a generic function that will allow him to specify which type the function should return. While implementing this, Miki demonstrates how the compiler may not recognise a type and methods to circumvent this issue. Watch and learn how to define a generic function and limit the types accepted by the function with an interface.

Things you will learn in this video

- Define a generic function.
- Explicitly pass a type to a generic function.
- Constrain accepted types of generic functions with interfaces.

--- 

### Video

<div class="post-video-container">
	<iframe
	    width="640"
	    height="480"
	    src="https://www.youtube.com/embed/34ZmIfWOb0U"
	    frameborder="0"
	    allow="autoplay; encrypted-media"
	    allowfullscreen
	>
	</iframe>
</div>
