Created
May 11, 2020 10:31
-
-
Save austin-sa-wang/01f19986a83811c045d21c98abe90c99 to your computer and use it in GitHub Desktop.
functor exercise 1
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
public async isValidEndDateFantasy (offeringId: number, endDate: string) { | |
// doLoadOffering :: number -> Promise(Either(AppError, Offering)) | |
const loadOffering = new Task((reject, result) => { | |
this.Models.Offering.load(offeringId) | |
.then((offering) => { | |
if (isNil(offering)) { | |
return reject(new AppError(`OfferingId ${offeringId} did not correspond to an offering`)) | |
} | |
return result(offering) | |
}) | |
}) | |
const isBefore = curry((dateA, dateB) => moment.utc(dateA).isBefore(dateB)) | |
// isBefore = | |
const forgivingIsBefore = (dateA) => maybe(true, isBefore(dateA)) | |
// getAvailabilityEnd :: Offering -> Maybe(string) | |
const getAvailabilityEnd = (offering) => { | |
return Maybe.of(offering.availabilityEnd) | |
} | |
// getAvailabilityEndDate :: Offering -> Maybe(Date) | |
const getAvailabilityEndDate = compose( | |
moment.utc, | |
getAvailabilityEnd | |
) | |
// doIt :: number -> Task(AppError, Offering) -> Maybe(Date) -> boolean | |
const doIt = compose( | |
forgivingIsBefore(dateA), | |
map(getAvailabilityEndDate) , | |
loadOffering | |
) | |
return doIt(offering) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment