What is a variadic function?

A variadic function is simply a function that accepts 0 or more items of the same type.

What uses variadic functions?

If you have ever used the print statement then you have used variadic function. If we click into it’s signature, then we get the following

public func print(_ items: Any..., separator: String = " ", terminator: String = "\n")

The print function accepts any amount of items that are of type Any. Which allows us to print multiple object by separating them with a comma.

Let’s make our own variadic function

To do so, we declare the parameter type…


An optional can either hold a value or nothing(nil) and we can unwrap them with guard let, if let and nil coalescing. With these three ways to accomplish the same task, how do you choose which one to use?

guard let

guard let is my preferred way to unwrap an optional but it can’t be used for any task. You want to use guard let when the optional value does not exist the rest of your function should not run.

func addFive(to number: Int?) -> Int {
// If the value is nil (does not exist)…

Setting Up

  1. Install the AWS CLI, I will be using version 2.
  2. Log into AWS console and head over to AWS SES and verify your email to in order for you to receive emails. For you to send emails without needing to verify you would need to contact AWS to lift that restriction from you.

Creating Template

Below is a sample template (sample.json)

{ "Template": { "TemplateName": "SampleTemplate", "SubjectPart": "Your Sample Email","TextPart": "Hi {{first_name}} {{last_name}},\n\nWelcome to AWS Simple Email Service (SES) to send emails with Golang.\n\n Best,\n\nYour Friend","HtmlPart": "Hi {{first_name}} {{last_name}},<br><br>Welcome to AWS Simple Email Service (SES) to…


What is a queue?

a list of data items, commands, etc., stored so as to be retrievable in a definite order, usually the order of insertion.

So with the definition out of way how can we implement it? Well we could build a wrapper around a list and implement the method we want around it like so

class Queue {

private var items: [Int] = []

var isEmpty: Bool {
get {…


Find Range I

Given a sorted array of numbers, find the first range of numbers that contains the target. A range contains the target if low <= target <= high. If a range does not exist return [-1, -1]

Example:
Array: [1, 2, 3, 4, 5, 6]
Target: 4
Output: [3, 4]

Array: [1, 2, 3, 4, 5, 6]
Target: 0
Output: [-1, -1]

Give it a shot, then come back if you get stuck or find a solution.

Solution #1

The first solution is really straight forward, we start at the second element and as we go through the array we check if the target is between the previous and current value. If at any point, the target value…

Jesus Bernal

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store