-
Notifications
You must be signed in to change notification settings - Fork 0
Phonebook #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Phonebook #6
Conversation
| let addTest () = | ||
| let book = addPhone "Oleg" "12345" book | ||
|
|
||
| book |> should contain {Name = "Oleg"; Phone = "12345"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
здесь было бы лучше проверить весь справочник. Вдруг addPhone перетирает остальные записи?
Phonebook/Phonebook/Program.fs
Outdated
| let command = getCommand () | ||
| match command with | ||
| | "0" -> () | ||
| | "1" -> addPhone (getName ()) (getPhone ()) book |> program |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
было бы немного читабельнее
| | "1" -> addPhone (getName ()) (getPhone ()) book |> program | |
| | "1" -> book |> addPhone (getName ()) (getPhone ()) |> program |
Phonebook/Phonebook/PhonebookFunc.fs
Outdated
| // поиск имени по телефону | ||
| let rec findNameByPhone phone (book : BookOfNumber list) = | ||
| let getFirst ({Name = a; Phone = b} : BookOfNumber) = a | ||
| book |> List.filter (fun {Name = _; Phone = x} -> x = phone) |> List.map(getFirst) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Можно записать так
| book |> List.filter (fun {Name = _; Phone = x} -> x = phone) |> List.map(getFirst) | |
| book |> List.filter (fun {Phone = x} -> x = phone) |> List.map(fun {Name = x} -> x) |
| let person (book : BookOfNumber list) = book.Head | ||
| if (not(book |> List.isEmpty)) then | ||
| printf "%s %s\n" (person book).Name (person book).Phone | ||
| printAll book.Tail |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
проще было бы через паттерн-матчинг со списком записать
No description provided.