This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| employeeFromDbToApplication : EmployeeFromDb1 -> List Employee1 -> Employee1 | |
| employeeFromDbToApplication (EmployeeFromDb1 empDb) employees = | |
| Employee1 | |
| { id = empDb.id | |
| , name = empDb.name | |
| , age = empDb.age | |
| , employees = employees | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type alias Table1 = | |
| List EmployeeFromDb1 | |
| lookUpEmployee1 : Id -> Table -> Maybe Employee1 | |
| lookUpEmployee1 id table = | |
| table | |
| |> List.filter (\employee -> employee.id == id) | |
| |> List.head |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type EmployeeFromDb1 | |
| = EmployeeFromDb1 | |
| { id : Id | |
| , name : String | |
| , age : Int | |
| , employerId : Id | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type alias Id = | |
| Int | |
| type Employee1 | |
| = Employee1 | |
| { id : Id | |
| , name : String | |
| , age : Int | |
| , employees : List Employee1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| map : (a -> b) -> Employee a -> Employee b | |
| map f (Employee sharedData a) = | |
| Employee sharedData (f a) | |
| replace : b -> Employee a -> Employee b | |
| replace b = | |
| map (\_ -> b) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| employeeAppToEmployeeCount : EmployeeApp -> EmployeeWithCount | |
| employeeAppToEmployeeCount employeeApp = | |
| map (\employees -> List.length employees) employeeApp |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| zero :: FreeMonoid t | |
| zero = Zero | |
| (<>) :: FreeMonoid t -> FreeMonoid t -> FreeMonoid t | |
| Zero <> x = x -- Left identity | |
| x <> Zero = x -- Right identity | |
| (Combine t1 rest1) <> x = | |
| -- `(a <> b) <> x` is represented as `a <> (b <> x)` | |
| Combine t1 (rest1 <> x) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| interpret :: b -> (a -> b -> b) -> FreeMonoid a -> b | |
| interpret myZero myCombine Zero = myZero | |
| interpret myZero myCombine (Combine a rest) = | |
| a `myCombine` (interpret myZero myCombine rest) -- a `Combine` (b `Combine` Zero) -> a `myCombine` (b `myCombine` myZero) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| isAdmin :: FreeMonoid (String, Bool) -> Bool | |
| isAdmin perms = interpret True (\(_, perm) rest -> perm && rest) perms | |
| isPowerUser :: FreeMonoid (String, Bool) -> Bool | |
| isPowerUser perms = interpret False (\(_, perm) rest -> perm || rest) perms | |
| isRegularUser :: FreeMonoid (String, Bool) -> Bool | |
| isRegularUser perms = not (isPowerUser perms) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| data FreeMonoid1 t | |
| = Zero | |
| | Val t | |
| | Combine (FreeMonoid1 t) (FreeMonoid1 t) |