CodeGrade Utils#

maybe_input(prompt, dflt='')[source]#

Queries the user for an input.

Parameters:
  • prompt (str) – The question to ask the user.

  • dflt (str) – Default return value.

Returns:

A Just of the user’s answer or default, or Nothing in case of error.

Return type:

Just[str] | _Nothing[str]

select_from_list(prompt, lst, make_label)[source]#

Queries the user to select one of the values from a list.

Parameters:
  • prompt (str) – The question to ask the user.

  • lst (Iterable[TypeVar(T)]) – The list from which to select.

  • make_label (Callable[[TypeVar(T)], str]) – A function that generates a label for each value in the list.

Returns:

A Just of the value selected by the user, or Nothing if the selection is invalid

Return type:

Maybe[T]

value_or_exit(maybe_value, err_message='Value was undefined')[source]#

Get the value from a Maybe or exit the program with an error message.

Parameters:
Returns:

The contained value.

Return type:

T