Skip to content

pfun.console.Console dataclass

Module that enables printing to stdout and reading from stdin

input(self, prompt='')

Get an effect that reads from stdin

Examples:

1
2
3
4
>>> greeting = lambda name: f'Hello {name}'
>>> Console().input('What is your name? ').map(greeting).run(None)
what is your name?  # input e.g "John Doe"
'Hello John Doe!'

Parameters:

Name Type Description Default
prompt str

Prompt to dislay on stdout

''

Returns:

Type Description
pfun.effect.Effect[object, NoReturn, str]

Effect that reads from stdin

print(self, msg='')

Get an effect that prints to stdout

Examples:

1
2
>>> Console().print('Hello pfun!').run(None)
Hello pfun!

Parameters:

Name Type Description Default
msg str

Message to print

''

Returns:

Type Description
pfun.effect.Effect[object, NoReturn, NoneType]

Effect that prints msg to stdout

pfun.console.HasConsole

Module provider providing the console module

pfun.console.print_line(msg='')

Get an Effect that prints to the console and succeeds with None

Examples:

1
2
3
4
>>> class Env:
...     console = Console()
>>> print_line('Hello pfun!').run(Env())
Hello pfun!

Parameters:

Name Type Description Default
msg str

Message to print

''

Returns:

Type Description
pfun.effect.Effect[pfun.console.HasConsole, NoReturn, NoneType]

Effect that prints to the console using the HasConsole provided to run

pfun.console.get_line(prompt='')

Get an Effect that reads a str from stdin

Examples:

1
2
3
4
5
6
>>> class Env:
...     console = Console()
>>> greeting = lambda name: f'Hello {name}!'
>>> get_line('What is your name? ').map(greeting).run(Env())
name?  # input e.g 'John Doe'
'Hello John Doe!'

Parameters:

Name Type Description Default
prompt str

prompt to display in console

''

Returns:

Type Description
pfun.effect.Effect[pfun.console.HasConsole, NoReturn, str]

an Effect that produces a str read from stdin