コード例 #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
ファイル: hello2.py プロジェクト: Technologicat/OSlash
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!")