From 1f79c7468b7860b5d0e800841798484e08ed7c9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20Sk=C3=A5nberg-Tippen?= Date: Tue, 6 Aug 2019 11:44:53 +0100 Subject: [PATCH] Remove named returns (plus a little tidy) --- examples/basic/basic.go | 3 ++- examples/handlers/handlers.go | 3 ++- examples/types/types.go | 3 ++- go.mod | 2 ++ interval.go | 8 +++++--- timespan.go | 29 +++++++++++------------------ 6 files changed, 24 insertions(+), 24 deletions(-) diff --git a/examples/basic/basic.go b/examples/basic/basic.go index 1ebccc7..0adb21d 100644 --- a/examples/basic/basic.go +++ b/examples/basic/basic.go @@ -2,8 +2,9 @@ package main import ( "fmt" - timespan "github.com/senseyeio/spaniel" "time" + + timespan "github.com/senseyeio/spaniel" ) func main() { diff --git a/examples/handlers/handlers.go b/examples/handlers/handlers.go index c00cfb3..2c8e70d 100644 --- a/examples/handlers/handlers.go +++ b/examples/handlers/handlers.go @@ -2,9 +2,10 @@ package main import ( "fmt" - timespan "github.com/senseyeio/spaniel" "sort" "time" + + timespan "github.com/senseyeio/spaniel" ) // PropertyEvent represents an event with an associated list of property strings. diff --git a/examples/types/types.go b/examples/types/types.go index 6ea582e..4f7e990 100644 --- a/examples/types/types.go +++ b/examples/types/types.go @@ -2,8 +2,9 @@ package main import ( "fmt" - timespan "github.com/senseyeio/spaniel" "time" + + timespan "github.com/senseyeio/spaniel" ) func main() { diff --git a/go.mod b/go.mod index b760806..cbd5dd7 100644 --- a/go.mod +++ b/go.mod @@ -1 +1,3 @@ module github.com/senseyeio/spaniel + +go 1.12 diff --git a/interval.go b/interval.go index a7d911a..1fea8c8 100644 --- a/interval.go +++ b/interval.go @@ -294,7 +294,7 @@ func (s Spans) Intersection() Spans { } // IntersectionBetweenWithHandler returns a list of pointers to Spans representing the overlaps between the contained spans -// and a given set of spans. +// and a given set of spans. It calls intersectHandlerFunc for each pair of spans that are intersected. func (s Spans) IntersectionBetweenWithHandler(candidates Spans, intersectHandlerFunc IntersectionHandlerFunc) Spans { intersections := Spans{} for _, candidate := range candidates { @@ -302,9 +302,9 @@ func (s Spans) IntersectionBetweenWithHandler(candidates Spans, intersectHandler i := Spans{candidate, span}.IntersectionWithHandler(func(a, b, s Span) Span { if a == candidate { return intersectHandlerFunc(a, b, s) - } else { - return intersectHandlerFunc(b, a, s) } + + return intersectHandlerFunc(b, a, s) }) intersections = append(intersections, i...) } @@ -312,6 +312,8 @@ func (s Spans) IntersectionBetweenWithHandler(candidates Spans, intersectHandler return intersections } +// IntersectionBetween returns the slice of spans representing the overlaps between the contained spans +// and a given set of spans. func (s Spans) IntersectionBetween(b Spans) Spans { return s.IntersectionBetweenWithHandler(b, func(intersectingEvent1, intersectingEvent2, intersectionSpan Span) Span { return intersectionSpan diff --git a/timespan.go b/timespan.go index 3024db2..6e33a9d 100644 --- a/timespan.go +++ b/timespan.go @@ -1,8 +1,8 @@ package spaniel import ( - "time" "encoding/json" + "time" ) // TimeSpan represents a simple span of time, with no additional properties. It should be constructed with NewEmpty. @@ -82,32 +82,25 @@ func (ts *TimeSpan) UnmarshalJSON(b []byte) (err error) { ts.start = i.Start ts.end = i.End - ts.startType = endPointIncluseionUnmarhsal(i.StartIncluded) - ts.endType = endPointIncluseionUnmarhsal(i.EndIncluded) + ts.startType = endPointInclusionUnmarhsal(i.StartIncluded) + ts.endType = endPointInclusionUnmarhsal(i.EndIncluded) return } -func endPointInclusionMarshal(e EndPointType) (included bool) { - switch e { - case Open: - included = false - case Closed: - included = true +func endPointInclusionMarshal(e EndPointType) bool { + if e == Open { + return false } - return included + return true } -func endPointIncluseionUnmarhsal(b bool) (e EndPointType) { - switch b { - case true: - e = Closed - case false: - e = Open +func endPointInclusionUnmarhsal(b bool) EndPointType { + if b == true { + return Closed } - - return e + return Open } // NewWithTypes creates a span with just a start and end time, and associated types, and is used when no handlers are provided to Union or Intersection.