-
Notifications
You must be signed in to change notification settings - Fork 4
Unit
Peter Nerg edited this page Jan 11, 2016
·
1 revision
Represents the type scala.Unit.
The usage of Unit is for situations where one returns types such as Try or Future that are not meant to hold a value.
E.g.
Try<Unit> deleteSynchronous(String id)
Future<Unit> deleteAsynchronous(String id)
The example illustrates deleting something but the only thing we care of is if the operation was successful.
This becomes very apparent with the asynchronous method. In that case we only care if the operation is finished and successful.
One can of course return dummy objects/values but providing Unit is more concise as it clearly marks a non-value.
Instead of creating new instances it is recommended to use the Unit.Instance singleton instance.
Also refer to the pages on Try and Future to find examples on writing side effecting Try and Future clauses that automatically return Unit
- Introduction
- JavaDoc (Latest)
- Containers
- Option/Some/None
- Try/Success/Failure
- Either/Left/Right
- Asynchronous Execution
- Future/Promise
- Companion Classes
- The Unit Type
- Testing/Asserts
- License
- Chat room for the project:
- Continuous Integration: