Skip to content

Instantly share code, notes, and snippets.

Avatar

Burak Serdar bserdar

View GitHub Profile
@bserdar
bserdar / goerrors.md
Created Oct 22, 2018
More explicit error handling
View goerrors.md

This is a suggestion to make error handling more explicit than what's described in the official proposal.

An error handler is declared as:

handle err { return err }

This declares err as an error variable, and an err_handler as a

@bserdar
bserdar / streams.md
Created Oct 26, 2018
Java stream lookalike in Go
View streams.md
package main

import (
	"fmt"
)

type Stream func() (int,bool)

func (s Stream) Filter(pred func(int) bool) Stream {
@bserdar
bserdar / gocontracts.md
Last active Nov 22, 2018
Types are contracts
View gocontracts.md

v2:

This started as a thought experiment after I read the Go generics and contracts proposal. The original proposal is powerful enough to specify precise type properties from the point of the generic implementor, however constraints such as "type T must support operator <" is over-specific in a language where < cannot be redefined. Such a constraints means "T must be numeric or string". So this exercise is an extension of the idea that contracts should be specified in terms of existing types, not in terms of type capabilities.