https://github.com/ubaldop/flat-challenge
Simple project implementing a module for array flattening
https://github.com/ubaldop/flat-challenge
Last synced: 3 months ago
JSON representation
Simple project implementing a module for array flattening
- Host: GitHub
- URL: https://github.com/ubaldop/flat-challenge
- Owner: ubaldop
- License: mit
- Created: 2021-03-13T13:22:20.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2021-03-14T15:23:20.000Z (about 4 years ago)
- Last Synced: 2025-01-08T17:09:27.411Z (4 months ago)
- Language: Scala
- Size: 11.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# flat-challenge
Simple project implementing a module for array flattening
---
## Notes
It defines a trait for Scala Integers arrays flattening. Since unflattened arrays of integers might contain either `Int` or `Array[Int]`, Scala compiler results in an actual `Array[Any]` type. E.g.:
```scala
val in: Array[Any] = Array(1, 2, Array(3, 4, 5))
```So, in order to try to preserve a better type safety, I took the approach of implementing a method returning either a flattened `Array[Int]` if the original input was an actual array of arrays of integers or a `MatchError` otherwise:
```scala
def flatten(in: Array[Any]): Either[Throwable, Array[Int]]
```
As you may notice from the type signatures above, the method returns an actual `Array[Int]` after the flattening only if the provided input actually contains integers only.---
## Tests
Under `src/test/scala` you find a set of unit tests as well.