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
| // Sometimes, you might want to supply *some* config, but | |
| // not necessarily *all*. Maybe your password is really | |
| // secret, so you don't want to risk saving it in a config | |
| // file. In which case, you'll want to ask the user to enter | |
| // it when your script runs. | |
| // This interface provides a flexible approach, where | |
| // the user is prompted for a missing key when it's | |
| // requested - if a particular key isn't needed for a given | |
| // run, the user won't need to enter it. Of course, if the |
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
| const fl = require('fantasy-land') | |
| //- Lazy holds a vaue in a thunk, effectively delaying | |
| //- evaluation until required. This is useful when we're | |
| //- in a situation with either very large data set or | |
| //- cyclical data. | |
| //@ make stack-safe. | |
| //> type Lazy a = Unit -> a | |
| function Lazy(run) { |
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
| const daggy = require('daggy') | |
| const { uncurryN } = require('wi-jit') // Shameless plug :-) | |
| // We'll need these instances for an example later... | |
| Function.prototype.map = function (that) { | |
| return x => that(this(x)) | |
| } | |
| Function.prototype.ap = function (that) { | |
| return x => that(x)(this(x)) |
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
| const Task = require('data.task') | |
| const Either = require('fantasy-eithers') | |
| // data.task actually uses `ap` with reversed | |
| // arguments, as the spec originally did, so | |
| // this is an "old-fashioned" lift2. | |
| const lift2 = (f, a, b) => a.map(f).ap(b) | |
| const queens = [ 'Alyssa', 'Katya', 'Willam' ] |
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
| const fl = require('fantasy-land') | |
| //- Textbook rose tree. | |
| //+ type RoseTree a = { value :: a, children :: [RoseTree a] } | |
| function RoseTree(value, children) { | |
| if (this.constructor !== RoseTree) | |
| return new RoseTree(value, children) | |
| Object.assign(this, { value, children }) | |
| } |
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
| const Option = require('fantasy-options') | |
| const Either = require('fantasy-eithers') | |
| const Task = require('data.task') | |
| const { tagged } = require('daggy') | |
| const { Some, None } = Option | |
| const { Left, Right } = Either | |
| const Pair = tagged('_1', '_2') |
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
| const daggy = require('daggy') | |
| const { Loop, Done } = | |
| daggy.taggedSum({ Loop: ['b'] | |
| , Done: ['a'] }) | |
| Array.empty = () => [] | |
| const Pair = T => { | |
| const Pair_ = daggy.tagged('_1', '_2') |
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
| const Promise = require('fantasy-promises') | |
| const daggy = require('daggy') | |
| //- Regular `compose` - old news! | |
| //+ compose :: (b -> c) | |
| //+ -> (a -> b) | |
| //+ -> a -> c | |
| const compose = f => g => x => | |
| f(g(x)) |
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
| const daggy = require('daggy') | |
| const { uncurryN } = require('wi-jit') | |
| Array.prototype.empty = () => [] | |
| Sum = daggy.tagged('value') | |
| Sum.prototype.concat = function (that) { | |
| return Sum(this.value + that.value) | |
| } |
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
| const { tagged } = require('daggy') | |
| const Pair = tagged('_1', '_2') | |
| //+ data Store p s = Store (p -> s) p | |
| const Store = tagged('lookup', 'pointer') | |
| Array.prototype.equals = function (that) { | |
| return this.length === that.length | |
| && this.every((x, i) => x.equals ? x.equals(that[i]) |