Subscribe to the Ardan Labs Insider

You’ll get our FREE Video Series & special offers on upcoming training events along with notifications on our latest blog posts.

Included in your subscription
  • Access to our free video previews
  • Updates on our latest blog posts
  • Discounts on upcoming events

Valid email required.

Submit failed. Try again or message us directly at hello@ardanlabs.com.

Thank You for Subscribing

Check your email for confirmation.

Interfaces 101 : Implementing Generics with Interfaces Ep. 1

Author image

Ardan Labs

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.

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

Go Training

We have taught Go to thousands of developers all around the world since 2014. There is no other company that has been doing it longer and our material has proven to help jump start developers 6 to 12 months ahead of their knowledge of Go. We know what knowledge developers need in order to be productive and efficient when writing software in Go.

Our classes are perfect for both experienced and beginning engineers. We start every class from the beginning and get very detailed about the internals, mechanics, specification, guidelines, best practices and design philosophies. We cover a lot about "if performance matters" with a focus on mechanical sympathy, data oriented design, decoupling and writing production software.

Capital One
Cisco
Visa
Teradata
Red Ventures

Interested in Ultimate Go Corporate Training and special pricing?

Let’s Talk Corporate Training!

Join Our Online
Education Program

Our courses have been designed from training over 30,000 engineers since 2013, and they go beyond just being a language course. Our goal is to challenge every student to think about what they are doing and why.