Created
February 6, 2021 14:31
-
-
Save korzio/fabe2e92aa92f4500a615367051de0c8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type interState struct { | |
Return string // final token value | |
Save string // running value | |
} | |
func isNumber(s String) bool { /* ... */ } | |
// Tokens observable filter operator ... | |
Scan(func(_ context.Context, acc interface{}, elem interface{}) (interface{}, error) { | |
var state interState | |
state, isToken := acc.(interState) | |
state.Return = "" | |
if !isToken || (isNumber(state.Save) && isNumber(elem.(string)) { | |
state.Save += elem.(string) | |
} else { | |
state.Return = state.Save | |
state.Save = elem.(string) | |
} | |
return state, nil | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment