-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path#test.py#
54 lines (36 loc) · 979 Bytes
/
#test.py#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
def solution(xs):
# write your code in Python 3.6
x, xs = uncons(range(0,20))
print(x)
print(xs)
# f should be capable of handling all Cardinalities of input, xs
# so ideally its a heterogeneus list
def fmap(f, xs):
if len(xs) == 0: # case xs of []
return xs
else:
x2,xs2 = uncons(xs)
x2 = f(x2)
g = [x2] + [2]
return [x2] + fmap(f, xs2)
#someFunc will either be comparing a <-> b or a <-> bs
# f :: mempty -> x -> mempty
def foldr(f, mempty, xs):
x = f(mempty, xs.pop(0))
if len(xs) != 0:
out = foldr (f, x, xs)
return out
else:
return x
def foldrLookAhead(f, mempty, xs):
x = f(mempty, xs)
def uncons(xs):
if len(xs) != 0:
x = xs.pop(0)
return x, xs
def plusOne(x):
return x + 1
def plus(x,y):
return x + y
#print(fmap (plusOne, [i for i in range(0,9)]))
print(foldr(plus, 0, [i for i in range(0,9)]))