Пример #1
0
def appendValue(word) -> IO:
    return IO(word + " at " + str(datetime.now().microsecond))
Пример #2
0
def createIO(word) -> IO:
    return IO(word)
Пример #3
0
def toUpper(word) -> IO:
    return IO(word.upper())
Пример #4
0
rightResult = Right("Hello") | \
              (lambda word: Right(word + " Functional")) | \
              (lambda word: Right(word + " Python")) | \
              (lambda word: Right(word + " world")) | \
              (lambda word: Right(word.upper()))
print(rightResult)

newError = left.bind(lambda x: x + 1981)
print(newError)

###################
#       IO        #
###################
'''Another monad, this time the IO Monad like Haskell which allow you composition and transformation. 
   Just like in Haskell the IO it's lazy and it wont be evaluated until the value it's invoked.'''
ioMonad = IO("Hello world")
print(ioMonad)


def createIO(word) -> IO:
    return IO(word)


def toUpper(word) -> IO:
    return IO(word.upper())


def appendValue(word) -> IO:
    return IO(word + " at " + str(datetime.now().microsecond))

Пример #5
0
from oslash import Put, Get, IO

main = Put(
    "What is your name?",
    Get(lambda name: Put(
        "What is your age?",
        Get(lambda age: Put("Hello " + name + "!",
                            Put("You are " + age + " years old", IO(())))))))

if __name__ == "__main__":
    main()
Пример #6
0
from oslash import Put, Get, IO

main = Put("What is your name?",
         Get(lambda name:
           Put("What is your age?",
             Get(lambda age:
               Put("Hello " + name + "!",
                 Put("You are " + age + " years old",
                   IO()
                 )
               )
             )
           )
         )
       )

if __name__ == "__main__":
    print(main)
Пример #7
0
 def test_put_return(self) -> None:
     pm = MyMock()
     action = Put("hello, world!", IO())
     action()
     self.assertEqual(pm.value, "hello, world!")
Пример #8
0
 def test_put_return(self):
     pm = MyMock()
     p = Put("hello, world!", IO(()))
     p(print=pm.print)
     self.assertEqual(pm.value, "hello, world!")