コード例 #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
ファイル: test_maybe.py プロジェクト: stjordanis/OSlash
 def test_just_functor_law1(self):
     # fmap id = id
     x = Just(3)
     self.assertEqual(
         x.map(identity),
         x
     )
コード例 #4
0
ファイル: test_maybe.py プロジェクト: stjordanis/OSlash
    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
ファイル: test_maybe.py プロジェクト: stjordanis/OSlash
    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
ファイル: test_maybe.py プロジェクト: yuhangwang/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))
コード例 #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
ファイル: test_maybe.py プロジェクト: stjordanis/OSlash
    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
ファイル: test_maybe.py プロジェクト: stjordanis/OSlash
    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
ファイル: test_maybe.py プロジェクト: yuhangwang/OSlash
 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
ファイル: test_maybe.py プロジェクト: yuhangwang/OSlash
    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
ファイル: test_maybe.py プロジェクト: stjordanis/OSlash
 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
ファイル: test_maybe.py プロジェクト: stjordanis/OSlash
 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
ファイル: test_maybe.py プロジェクト: stjordanis/OSlash
 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
ファイル: test_maybe.py プロジェクト: stjordanis/OSlash
 def test_combine_just_or_nothing_rule1(self):
     self.assertEqual(
         Just(5) or Nothing,
         Just(5)
     )