1. Yes, Option<T> is one of the ways to express "optional" value. And T? is another one. They express the same meaning.

2. No, totality has nothing to do with the expected value. doubler2 in your example is defined for any integer. The fact that it returns null for some of them doesn't make this function partial.

If you say that doubler2 should return doubled input, but it returns null for 6 instead, it just means that this function is implemented incorrectly – it doesn't match the specification. But it's still total.

If you want to demonstrate the idea of a partial function, you can throw an exception for some input, as I suggested in the beginning. Or you can add infinite loop for some input. But null is a valid output from the totality point of view.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Kirill Bubochkin
Kirill Bubochkin

No responses yet

Write a response