Last active
December 18, 2019 04:03
-
-
Save ShelbyCohen/cacc26c156d0b3f8b3ed779a913411a2 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
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