In this exercise, you'll be implementing the quest logic for a new RPG game a friend is developing. The game's main character is Annalyn, a brave girl with a fierce and loyal pet dog Kazak. At one point they are ambushed by a monster which they attack.
Define attackWithSword1.
This should take a MonsterDamage (a String that describes the damage to the monster) and an Int that indicates how strong the attack is.
It should return the existing string, with "Attacked with sword of strength {strength}." appended to the end.
Define attackWithClaw1.
This should take a MonsterDamage and an Int that indicates how strong the attack is.
It should return the existing string, with "Attacked with claw of strength {strength}." appended to the end.
Annalyn attacks with a sword, and she has a strength of 5.
Her loyal pet dog Kazak attacks with its claws, and has a strength of 1.
Define attack1. This should take a MonsterDamage and perform the following attacks, in the correct order:
The implementation of this function will be a bit cumbersome, as attackWithSword1 and attackWithClaw1 do not have the main data structure (MonsterDamage) as the last parameter (they are not doing it in the recommended way).
It is not possible / advisable to use partial application in this initial case.
Define attackWithSword2.
This is the same as attackWithSword1, except the parameters are swapped.
Define attackWithClaw2.
This is the same as attackWithClaw2, except the parameters are swapped.
Define attack2.
This is the same as attack1, but should use attackWithSword2 and attackWithClaw2.
Please implement the function using Partial application and the pipe operator (|>).
The implementation should now be more elegant, as attackWithSword2 and attackWithClaw2 have MonsterDamage (the main data structure) as the last parameter, as is recommended.
Define attack3.
This is the same as attack2, but should be implemented using function composition / the (>>) operator.
This implementation should also be elegant, and smaller than attack2, although potentially harder to understand.
In this exercise, you'll be implementing the quest logic for a new RPG game a friend is developing. The game's main character is Annalyn, a brave girl with a fierce and loyal pet dog Kazak. At one point they are ambushed by a monster which they attack.
Define attackWithSword1.
This should take a MonsterDamage (a String that describes the damage to the monster) and an Int that indicates how strong the attack is.
It should return the existing string, with "Attacked with sword of strength {strength}." appended to the end.
Define attackWithClaw1.
This should take a MonsterDamage and an Int that indicates how strong the attack is.
It should return the existing string, with "Attacked with claw of strength {strength}." appended to the end.
Annalyn attacks with a sword, and she has a strength of 5.
Her loyal pet dog Kazak attacks with its claws, and has a strength of 1.
Define attack1. This should take a MonsterDamage and perform the following attacks, in the correct order:
The implementation of this function will be a bit cumbersome, as attackWithSword1 and attackWithClaw1 do not have the main data structure (MonsterDamage) as the last parameter (they are not doing it in the recommended way).
It is not possible / advisable to use partial application in this initial case.
Define attackWithSword2.
This is the same as attackWithSword1, except the parameters are swapped.
Define attackWithClaw2.
This is the same as attackWithClaw2, except the parameters are swapped.
Define attack2.
This is the same as attack1, but should use attackWithSword2 and attackWithClaw2.
Please implement the function using Partial application and the pipe operator (|>).
The implementation should now be more elegant, as attackWithSword2 and attackWithClaw2 have MonsterDamage (the main data structure) as the last parameter, as is recommended.
Define attack3.
This is the same as attack2, but should be implemented using function composition / the (>>) operator.
This implementation should also be elegant, and smaller than attack2, although potentially harder to understand.