コード例 #1
0
ファイル: test_iterators.py プロジェクト: soasme/fn.py
 def test_nth(self):
     self.assertEqual(1, iters.nth(range(5), 1))
     self.assertEqual(None, iters.nth(range(5), 10))
     self.assertEqual("X", iters.nth(range(5), 10, "X"))
コード例 #2
0
        return reduce3(f, xs[1:], f(xs[0], accumulator))
    else:
        return accumulator


falsify("reduce vs reduce1", lambda xs, s: reduce(add, xs, s) == reduce1(add, xs, s), [int], int)
falsify("reduce1 vs reduce2", lambda xs, s: reduce1(add, xs, s) == reduce2(add, xs, s), [int], int)
falsify("reduce2 vs reduce3", lambda xs, s: reduce2(add, xs, s) == reduce3(add, xs, s), [int], int)


# higher order cont
def doubles(xs):
    return map(lambda x: x * 2, xs)


falsify("doubles", lambda xs: not xs or nth(doubles(xs), 0) == xs[0] * 2, [int])


# partial application
def doubles1(xs):
    return map(partial(mul, 2), xs)


def doubles2(xs):
    return map(F(mul, 2), xs)


falsify("doubles vs double1", lambda xs: list(doubles(xs)) == list(doubles1(xs)), [int])
falsify("doubles1 vs double2", lambda xs: list(doubles1(xs)) == list(doubles2(xs)), [int])

コード例 #3
0
ファイル: tests.py プロジェクト: Gizmo707/fn.py
 def test_nth(self):
     self.assertEqual(1, iters.nth(range(5), 1))
     self.assertEqual(None, iters.nth(range(5), 10))
     self.assertEqual("X", iters.nth(range(5), 10, "X"))
コード例 #4
0
ファイル: collector.py プロジェクト: signalpillar/crawler
def second(xs):
    '@types: iterable[T] -> T?'
    return nth(xs, 1)