Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Functional Programming Through Construction : First Principles
1. @pcameronpresley@pcameronpresley
LEARNING FP THROUGH CONSTRUCTION:
FIRST PRINCIPLES
Cameron Presley
@pcameronpresley
Cameron@TheSoftwareMentor.com
Slides can be found at:
https://blog.TheSoftwareMentor.com/Presentations
6. @pcameronpresley@pcameronpresley
Objective
You are part of the team that explores Mars by
sending remotely controlled vehicles to the
surface of the planet.
Develop an API that translates the commands
sent from earth to instructions that are
understood by the rover.
7. @pcameronpresley@pcameronpresley
Requirements
▪ Know what the initial starting point (x,y) of a
rover and the direction (N,S,E,W) it is facing.
▪ Implement commands that move the rover
forward/backward (f,b).
▪ Implement commands that turn the rover
left/right (l,r).
8. @pcameronpresley@pcameronpresley
Requirements
▪ Know what the initial starting point (x,y) of
a rover and the direction (N,S,E,W) it is
facing.
▪ Implement commands that move the rover
forward/backward (f,b).
▪ Implement commands that turn the rover
left/right (l,r).
25. @pcameronpresley@pcameronpresley
Requirements
▪ Know what the initial starting point (x,y) of
a rover and the direction (N,S,E,W) it is
facing.
▪ Implement commands that move the rover
forward/backward (f,b).
▪ Implement commands that turn the rover
left/right (l,r).
26. @pcameronpresley@pcameronpresley
Requirements
▪ Know what the initial starting point (x,y) of a
rover and the direction (N,S,E,W) it is facing.
▪ Implement commands that move the rover
forward/backward (f,b).
▪ Implement commands that turn the rover
left/right (l,r).
42. @pcameronpresley@pcameronpresley
Requirements
▪ Know what the initial starting point (x,y) of a
rover and the direction (N,S,E,W) it is facing.
▪ Implement commands that move the rover
forward/backward (f,b).
▪ Implement commands that turn the rover
left/right (l,r).
43. @pcameronpresley@pcameronpresley
Requirements
▪ Know what the initial starting point (x,y) of a
rover and the direction (N,S,E,W) it is facing.
▪ Implement commands that move the rover
forward/backward (f,b).
▪ Implement commands that turn the rover
left/right (l,r).
49. @pcameronpresley@pcameronpresley
Requirements
▪ Know what the initial starting point (x,y) of a
rover and the direction (N,S,E,W) it is facing.
▪ Implement commands that move the rover
forward/backward (f,b).
▪ Implement commands that turn the rover
left/right (l,r).
50. @pcameronpresley@pcameronpresley
Requirements
▪ Know what the initial starting point (x,y) of a
rover and the direction (N,S,E,W) it is facing.
▪ Implement commands that move the rover
forward/backward (f,b).
▪ Implement commands that turn the rover
left/right (l,r).
85. @pcameronpresley@pcameronpresley
Resources
▪ Videos
□ Professor Frisby Introduces Composable Functional JavaScript
▪ Articles
□ Thinking Functionally (Series) by Scott Wlaschin
▪ Books
□ Domain Modeling Made Functional by Scott Wlaschin
□ Professor Frisby's Mostly Adequate Guide to Functional
Programming by Brian Lonsdorf
□ Functional Light JavaScript by Kyle Simpson
▪ Code
□ FPThroughConstruction-Fundamentals (GitHub)
Could model like this
Any issues?
For the C# version, would need to make sure that all fields were specified first.
Anything wrong with this method?
What about this part? That seems to be a bit weird…
Based on the signature, I wouldn’t expect this to happen, but no way to enforce this…
* Here’s the definition for Rover
* Here’s the change we’ll make to prevent the issue from before (remove setter)
Once we change the type, the “wrongness” starts to really be obvious
Same object reference being used in multiple places…
Parallel Processing Code
Moving Forward can be thought of
Given a rover
A rover is returned
If the given rover is facing north
Then a rover is returned with a y that is one more than the previous
In other words, is there a reason why we couldn’t get a Rover back for any Rover facing a direction? (Onto)
In other words, is there any rover facing a direction where if we called this function, we’d get two different values? (one-to-one)
Not a function because one element in the first set is mapped to two different elements
Not a function because not ever element in the first set is mapped to an element in the second set
Moving Forward can be thought of
Given a rover
A rover is returned
If the given rover is facing north
Then a rover is returned with a y that is one more than the previous
If functions aren’t onto, that means there are use cases/results you have to “remember” to handle (no type system to help you out
If functions aren’t onto, that means there are use cases/results you must “remember” to handle (no type system to help you out
Any entry in the first set that has multiple outputs?
Any entry in the first set that’s not mapped to the second set?
Converting user input to Command
Clean Architecture
General Workflow Pattern (Data comes in, Gets Processed, Data Goes Out)
How many times do we need to process a list? (4 times, 1 per Select and 1 for the Aggregate)
Can only work if both functions to be composed are actually functions!
By composing, we get the iterations down to 2
If you see a Select, followed by Aggregate (or a Map followed by a Reduce), we can combine the two!