Ejemplo n.º 1
0
def appendValue(word) -> IO:
    return IO(word + " at " + str(datetime.now().microsecond))
Ejemplo n.º 2
0
def createIO(word) -> IO:
    return IO(word)
Ejemplo n.º 3
0
def toUpper(word) -> IO:
    return IO(word.upper())
Ejemplo n.º 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))

Ejemplo n.º 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()
Ejemplo n.º 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)
Ejemplo n.º 7
0
 def test_put_return(self) -> None:
     pm = MyMock()
     action = Put("hello, world!", IO())
     action()
     self.assertEqual(pm.value, "hello, world!")
Ejemplo n.º 8
0
 def test_put_return(self):
     pm = MyMock()
     p = Put("hello, world!", IO(()))
     p(print=pm.print)
     self.assertEqual(pm.value, "hello, world!")