Skip to content

Commit

Permalink
Replace if/else chain with a single switch statement
Browse files Browse the repository at this point in the history
Replacing the `if/else` chain with a single `switch` statement makes the code just a little more idiomatic.

Also ordered the variable declarations and `case` statements so they are all in the order of priority used by this function.

Last change is not specifically initializing the booleans to `false`. `false` is already the zero value of a `bool` so unless explicitely set to `true`, they will be `false`.
  • Loading branch information
Sander van Harmelen authored and kniren committed Jan 24, 2017
1 parent d121cbf commit 2012b3e
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions dataframe/dataframe.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,32 +566,31 @@ func (df DataFrame) Rapply(f func(series.Series) series.Series) DataFrame {
}

detectType := func(types []series.Type) series.Type {
hasFloats := false
hasInts := false
hasBools := false
hasStrings := false
var hasStrings, hasFloats, hasInts, hasBools bool
for _, t := range types {
switch t {
case series.Int:
hasInts = true
case series.String:
hasStrings = true
case series.Float:
hasFloats = true
case series.Int:
hasInts = true
case series.Bool:
hasBools = true
case series.String:
hasStrings = true
}
}
if hasStrings {
switch {
case hasStrings:
return series.String
} else if hasFloats {
case hasFloats:
return series.Float
} else if hasInts {
case hasInts:
return series.Int
} else if hasBools {
case hasBools:
return series.Bool
default:
panic("type not supported")
}
panic("type not supported")
}

// Detect row type prior to function application
Expand Down

0 comments on commit 2012b3e

Please sign in to comment.