summaryrefslogtreecommitdiffstats
path: root/src/act4e_solutions/maps.py
blob: f056da88a1656a65eecdb3791a8d620aa569cf46 (plain)
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
from typing import TypeVar

import act4e_interfaces as I
from .maps_representation import MyFiniteMap

A = TypeVar("A")
B = TypeVar("B")
C = TypeVar("C")


class SolFiniteMapOperations(I.FiniteMapOperations):

    def identity(self, s: I.Setoid[A]) -> I.Mapping[A, A]:
        values = []
        for a in s.elements():
            values.append([a, a])

        return MyFiniteMap(s, s, values)


    def compose(self, f: I.FiniteMap[A, B], g: I.FiniteMap[B, C]) -> I.FiniteMap[A, C]:
        values = []
        for a in f.source().elements():
            values.append([a, g(f(a))])

        return MyFiniteMap(f.source(), g.target(), values)