Skip to content

Commit

Permalink
Merge pull request #12 from senseyeio/remove-named-returns
Browse files Browse the repository at this point in the history
Remove named returns (plus a little tidy)
  • Loading branch information
mikejewell authored Aug 6, 2019
2 parents d49b454 + 1f79c74 commit 5db91ae
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 24 deletions.
3 changes: 2 additions & 1 deletion examples/basic/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package main

import (
"fmt"
timespan "github.com/senseyeio/spaniel"
"time"

timespan "github.com/senseyeio/spaniel"
)

func main() {
Expand Down
3 changes: 2 additions & 1 deletion examples/handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion examples/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package main

import (
"fmt"
timespan "github.com/senseyeio/spaniel"
"time"

timespan "github.com/senseyeio/spaniel"
)

func main() {
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
module github.com/senseyeio/spaniel

go 1.12
8 changes: 5 additions & 3 deletions interval.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,24 +294,26 @@ 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 {
for _, span := range s {
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...)
}
}
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
Expand Down
29 changes: 11 additions & 18 deletions timespan.go
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 5db91ae

Please sign in to comment.