This file contains 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
// Helper Functions | |
const wrapWith = wrapper => obj => key => val => wrapper({...obj, [key]: val}); | |
const wrapWithSiteBuilder = wrapWith(SiteBuilder); | |
// Expression Builder | |
function SiteBuilder(value) { | |
const siteBuilderWrapper = wrapWithSiteBuilder(value); | |
return { | |
withSiteName: siteBuilderWrapper('name'), | |
withDomain: siteBuilderWrapper('domain'), |
This file contains 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
const SiteBuilder = value => ({ | |
withSiteName: name => SiteBuilder({...value, ...{name}}), | |
withDomain: domain => SiteBuilder({...value, ...{domain}}), | |
build: () => value | |
}); | |
const site = SiteBuilder({}) | |
.withSiteName('hello') | |
.withDomain('some-domain') | |
.build(); |
This file contains 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
const withSecurityEnabled = set(lensPath([‘services’, ‘securityEnabled’])) |
This file contains 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
const withSiteName = set(lensProp('name')); | |
const withDomain = set(lensProp('domain')); | |
const site = pipe(withSiteName('a Site'), withDomain('domain')); | |
site({}); // site is the function that returns the value |
This file contains 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
class SiteBuilder { | |
private site: any; | |
withSiteName(name: string) { | |
this.site.name = name; | |
return this; | |
} | |
withDomain(domain: string) { | |
this.site.domain = domain; | |
return this; |
This file contains 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
const theSite = new SiteBuilder() | |
.withSiteName('a Site') | |
.withDomain('www.some-domain.com') | |
.build(); |
This file contains 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
expect(someValue).to.equal(expectedValue) |