Skip to content

Instantly share code, notes, and snippets.

@chadyred
Created August 29, 2018 14:38
Show Gist options
  • Save chadyred/8e2e84c80e1f712e0e233b00f9c3595d to your computer and use it in GitHub Desktop.
Save chadyred/8e2e84c80e1f712e0e233b00f9c3595d to your computer and use it in GitHub Desktop.
Try
#!/usr/bin/python3
import abc
from typing import Callable, IO, cast
from east_displayer import Output, OutputStream
from east_typer import StringComputer, String, StringReceiver, ReceiverOfString
class MessageTemplating(metaclass=abc.ABCMeta):
@abc.abstractmethod
def recipient_of_message_templatize_is(self, receiver: 'ReceiverOfString') -> 'MessageTemplating':
"""Message factoring"""
class Messagerable(metaclass=abc.ABCMeta):
@abc.abstractmethod
def recipient_to_output_with_string_is(self, message: 'String', receiver_output: 'Output') -> 'Messagerable':
"""Message factoring"""
return self
class MessagerTemplate(MessageTemplating):
def recipient_of_message_templatize_is(self, message: 'String', receiver: 'ReceiverOfString') -> 'MessageTemplating':
"""Show notice"""
message.recipient_of_string_is(
StringReceiver(
lambda message: String("Notice : " + message + '\n').recipient_of_string_is(receiver)
)
)
return self
class Messager(Messagerable):
def __init__(self, template: 'MessageTemplating' = MessagerTemplate()):
self.template = template
def recipient_to_output_with_string_is(self, message: 'String', receiver_output: 'Output') -> 'Messagerable':
self.template.recipient_of_message_templatize_is(
message,
StringReceiver(
lambda message_well_formated: String(message_well_formated).recipient_of_string_is(
StringReceiver(
lambda end_message: receiver_output.output_value_is(end_message)
)
)
)
)
return self
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment