예제 #1
0
파일: test_maybe.py 프로젝트: cbenz/OSlash
    def test_maybe_monoid_just_append_nothing(self):
        m = Just("Python")

        self.assertEquals(
            m.append(Nothing()),
            m
        )
예제 #2
0
파일: test_maybe.py 프로젝트: cbenz/OSlash
 def test_just_functor_law1(self):
     # fmap id = id
     x = Just(3)
     self.assertEquals(
         x.map(identity),
         x
     )
예제 #3
0
 def test_just_functor_law1(self):
     # fmap id = id
     x = Just(3)
     self.assertEqual(
         x.map(identity),
         x
     )
예제 #4
0
    def test_maybe_monoid_just_append_just(self):
        m = Just("Python")
        n = Just(" rocks!")

        self.assertEqual(
            m + n,
            Just("Python rocks!")
        )
예제 #5
0
파일: test_maybe.py 프로젝트: cbenz/OSlash
    def test_just_functor_map(self):
        f = lambda x: x*2
        x = Just(21)

        self.assertEquals(
            x.map(f),
            Just(42)
        )
예제 #6
0
    def test_just_functor_map(self):
        f = lambda x: x * 2
        x = Just(21)

        self.assertEqual(
            x.map(f),
            Just(42)
        )
예제 #7
0
파일: test_maybe.py 프로젝트: cbenz/OSlash
    def test_maybe_monoid_just_append_just(self):
        m = Just("Python")
        n = Just(" rocks!")

        self.assertEquals(
            m.append(n),
            Just("Python rocks!")
        )
예제 #8
0
    def test_just_functor_law2(self):
        # fmap (f . g) x = fmap f (fmap g x)
        def f(x):
            return x + 10

        def g(x):
            return x * 10

        x = Just(42)

        self.assertEquals(x.map(compose(f, g)), x.map(g).map(f))
예제 #9
0
파일: test_maybe.py 프로젝트: cbenz/OSlash
    def test_just_functor_law2(self):
        # fmap (f . g) x = fmap f (fmap g x)
        def f(x):
            return x+10

        def g(x):
            return x*10

        x = Just(42)

        self.assertEquals(
            x.map(compose(f, g)),
            x.map(g).map(f)
        )
예제 #10
0
    def test_maybe_monoid_just_append_nothing(self):
        m = Just("Python")

        self.assertEqual(
            m + Nothing(),
            m
        )
예제 #11
0
def get_url(search_results):
    rtn = []
    for a in search_results.find_all('a'):
        rtn.append(a['href'])
    if len(rtn) == 0:
        return Nothing
    else:
        return Just(rtn)
예제 #12
0
파일: dp.py 프로젝트: vulogov/core.F
 def _get(self, _p, _fp, _d, default):
     if len(_p) == 1:
         try:
             if isinstance(_d, dict) is True:
                 return Just(_d[_p[0]])
             if isinstance(_d, DP) is True:
                 return Just(_d.raw()[_p[0]])
             else:
                 return Nothing()
         except KeyError:
             if isinstance(default, Monad) is True:
                 return default
             else:
                 return Just(default)
     d = _d.get(_p[0], None)
     if _d.get(_p[0], None) is None:
         _fp.append(_p[0])
         d = self._mkdir(_d, _p[0], _fp)
     return self._get(_p[1:], _fp, d, default)
예제 #13
0
def get_result(name_version):
    theurl = "http://gpo.zugaina.org/Search?search=%s" % name_version
    thepage = urllib.request.urlopen(theurl)

    soup = BeautifulSoup(thepage, "lxml")

    # <div id="search_results">
    search_results = soup.find('div', id="search_results")
    if search_results:
        return Just(search_results)
    else:
        return Nothing
예제 #14
0
파일: dp.py 프로젝트: vulogov/core.F
 def _set(self, _p, _fp, _d, value):
     if len(_p) == 1:
         if isinstance(value, Monad) is True:
             _d[_p[0]] = value.value
             return value
         else:
             #print("GGG",_p[0], type(_d), _d,value)
             _d[_p[0]] = value
             return Just(value)
     d = _d.get(_p[0], None)
     if _d.get(_p[0], None) is None:
         _fp.append(_p[0])
         d = self._mkdir(_d, _p[0], _fp)
     return self._set(_p[1:], _fp, d, value)
예제 #15
0
    def test_maybe_monoid_concat(self):

        self.assertEqual(
            Maybe.concat([Just(2), Just(40)]),
            Just(42)
        )
예제 #16
0
 def test_combine_just_and_just_rule1(self):
     self.assertEquals(Just(5) and Just(6), Just(6))
예제 #17
0
 def test_just_applicative_1(self):
     a = Just.pure(lambda x, y: x + y).apply(Just(2)).apply(Just(40))
     self.assertNotEquals(a, Nothing())
     self.assertEquals(a, Just(42))
예제 #18
0
    def test_maybe_monoid_nothing_append_just(self):
        m = Just("Python")

        self.assertEquals(Nothing().append(m), m)
예제 #19
0
파일: test_maybe.py 프로젝트: cbenz/OSlash
 def test_just_applicative_3(self):
     a = Just.pure(lambda x, y: x+y).apply(Just(42)).apply(Nothing())
     self.assertEquals(a, Nothing())
예제 #20
0
 def test_just_applicative_3(self):
     a = Just.pure(lambda x, y: x+y).apply(Just(42)).apply(Nothing())
     self.assertEqual(a, Nothing())
예제 #21
0
 def test_combine_just_or_nothing_rule2(self):
     self.assertEqual(
         Just(0) or Nothing,
         Nothing
     )
예제 #22
0
def get_category(url_list):
    if len(url_list) == 1:
        return Just(url_list[0])
    else:
        return Nothing
예제 #23
0
 def test_combine_just_and_just_rule2(self):
     self.assertEqual(
         Just(0) and Just(6),
         Just(0)
     )
예제 #24
0
from oslash.maybe import Just, Nothing

Value = Just
NONE = Nothing()
TRUE = Just(True)
FALSE = Just(False)


def isNothing(x):
    return x is None or x == NONE or isinstance(x, Nothing)
예제 #25
0
 def test_combine_just_or_nothing_rule1(self):
     self.assertEqual(
         Just(5) or Nothing,
         Just(5)
     )