Skip to content

Instantly share code, notes, and snippets.

@ShelbyCohen
Last active December 18, 2019 04:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ShelbyCohen/cacc26c156d0b3f8b3ed779a913411a2 to your computer and use it in GitHub Desktop.
Save ShelbyCohen/cacc26c156d0b3f8b3ed779a913411a2 to your computer and use it in GitHub Desktop.
val toIntegerStream = Function<String, Flux<Int>> { string ->
Flux.fromIterable(IterableSpliterator.of(string.chars().boxed().spliterator()))
}
val histoOfLetters = Function<String, Flux<HashMap<Int, LongWrapper>>> { word ->
Flux.from(toIntegerStream.apply(word)
.collect(
{ HashMap() },
{ map: HashMap<Int, LongWrapper>, value: Int ->
var newValue: LongWrapper? = map[value]
if (newValue == null) {
newValue = LongWrapper.zero()
}
map[value] = newValue.incAndSet()
}
))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment