Skip to content

Instantly share code, notes, and snippets.

View DylanSp's full-sized avatar

Dylan Sprague DylanSp

View GitHub Profile
interface ILogger {
log: (str: string) => void;
}
class Logger implements ILogger {
log = (str: string): void => {
console.log(str);
};
}
@DylanSp
DylanSp / option_struct.go
Last active July 5, 2022 13:14
Option type in Go as a struct with a boolean flag
package main
import (
"fmt"
)
// begin Option package
type Option[T any] struct {
hasValue bool
@DylanSp
DylanSp / phantom_types.go
Created July 4, 2022 23:33
Phantom types in Go
package main
import (
"fmt"
"github.com/google/uuid"
)
// with this, the "value" field can't be accessed outside the package with PhantomID,
// which prevents PhantomID[T] from being compared to PhantomID[U]