Skip to content

Instantly share code, notes, and snippets.

Avatar

Burak Serdar bserdar

View GitHub Profile
@bserdar
bserdar / streams.md
Created October 26, 2018 03:41
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 November 22, 2018 04:12
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.

@bserdar
bserdar / goerrors.md
Created October 22, 2018 14:29
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