mediocregopher / seq

A go library providing clojure-like immutable data-structures and functional ways to interact with them

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

seq.NewSet() returns nil

tfgordon opened this issue · comments

instead of an empty set.

I'm not sure that returning nil is the actual problem. The symptom is that seq.NewSet().Size()-1 returns a large positive integer:

package main

import(
    "fmt"
    "github.com/mediocregopher/seq"
)

func main(){    
    fmt.Printf("%v\n", seq.NewSet().Size()-1)
}

Presumably because .Size() returns an unsigned integer.

right. nil is a valid value for Set, it's just a Set with no items. The problem is you're subtracting 1 from 0 in an unsigned integer, so it overflows and goes back to a high number. if you wrap the Size() call in int() or int64() you'll get the behavior you want.