### Install project dependencies Source: https://github.com/origamitower/folktale/blob/master/docs/_docs/v2.3.0/contributing/bugfixes.md Run this command in the project root to install necessary development tools. ```bash $ npm install ``` -------------------------------- ### Install project dependencies Source: https://github.com/origamitower/folktale/blob/master/docs/_docs/v2.3.0/contributing/setup.md Navigate into the cloned Folktale directory and install all project dependencies and development tools using npm. ```bash cd folktale $ npm install ``` -------------------------------- ### Run a Task and Get a Future Source: https://github.com/origamitower/folktale/blob/master/docs/api/v2.3.0/en/folktale.concurrency.future.html Example of creating a Task and running it to obtain a Future, then mapping over its resolved value. Ensure the Task is resolved to see the mapped value. ```javascript const { task } = require('folktale/concurrency/task'); const one = task(resolver => resolver.resolve(1)); one.run().future().map(value => { $ASSERT(value == 1); }); ``` -------------------------------- ### Install Folktale using npm Source: https://github.com/origamitower/folktale/wiki/Installing-Folktale Run this command in your terminal to install Folktale. Ensure you have Node.js and npm installed. ```bash $ npm install folktale ``` -------------------------------- ### Install Browserify for Development Source: https://github.com/origamitower/folktale/wiki/Installing-Folktale Install Browserify as a development dependency using npm. This is required for bundling modules in the browser. ```bash $ npm install browserify --save-dev ``` -------------------------------- ### Install Meta:Magical Dependencies Source: https://github.com/origamitower/folktale/wiki/REPL-documentation Install the necessary packages for using Meta:Magical with Folktale. Ensure you are using the specified version ranges. ```shell npm install metamagical-interface@3.4.x npm install metamagical-repl@0.3.x ``` -------------------------------- ### Browserify Example with Folktale Modules Source: https://github.com/origamitower/folktale/wiki/Installing-Folktale Import specific Folktale modules like Maybe and compose to keep your bundle size small. This example shows mapping a composed function over a Maybe.Just value. ```javascript const Maybe = require('folktale/data/maybe'); const compose = require('folktale/core/lambda/compose'); const inc = (x) => x + 1; const double = (x) => x * 2; Maybe.Just(1).map(compose(inc, double)); // ==> Maybe.Just(4) ``` -------------------------------- ### Example Commit with Test Tag Source: https://github.com/origamitower/folktale/blob/master/docs/_docs/v2.3.0/contributing/git-guidelines.md An example commit demonstrating the use of the 'test' tag for changes related to testing, including a summary, detailed explanation, and issue reference. ```git (test) Adds tests for compose `compose` was the only function in the module that didn't have tests. This provides a few example based tests, and property-based tests for common mathematical laws expected of function composition, such as associativity. Fixes #12 ``` -------------------------------- ### Install WebPack for Development Source: https://github.com/origamitower/folktale/wiki/Installing-Folktale Install WebPack as a development dependency using npm. This is needed for bundling modules in the browser. ```bash $ npm install webpack --save-dev ``` -------------------------------- ### Install Folktale for Browser Usage Source: https://github.com/origamitower/folktale/wiki/Installing-Folktale Install Folktale as a project dependency. This command should be run in your project's root directory. ```bash $ npm install folktale --save ``` -------------------------------- ### Build Folktale documentation Source: https://github.com/origamitower/folktale/blob/master/docs/_docs/v2.3.0/contributing/setup.md Generate the project documentation using Furipota. This process requires Ruby, RubyGems, and Bundler to be installed. ```bash $ ./node_modules/.bin/furipota run documentation ``` -------------------------------- ### Feature request template example Source: https://github.com/origamitower/folktale/blob/master/docs/_docs/support/feature-request.md An example of how to format a feature request for a .concat method in Data.Validation. ```javascript const v1 = Validation.Failure(1); const v2 = Validation.Failure("error"); v1.concat(v2) // => Validation.Failure([1, "error"]) ``` -------------------------------- ### Use manual currying Source: https://github.com/origamitower/folktale/blob/master/annotations/source/en/core/lambda/curry.md Example of a manually curried function and its usage. ```javascript const joinedBy = (separator) => (list) => (item) => list.concat([separator, item]); ``` ```javascript joinedBy(',')(['a'])('b'); // ==> ['a', ',', 'b'] ``` ```javascript ['b'].reduce(joinedBy(','), ['a']); // ==> [, ] ``` -------------------------------- ### Initialize people data array Source: https://github.com/origamitower/folktale/blob/master/annotations/source/en/core/lambda/curry.md A sample array of objects representing people for use in mapping examples. ```javascript const people = [ { name: 'Alissa', age: 26, pronoun: 'she' }, { name: 'Max', age: 19, pronoun: 'they' }, { name: 'Talib', age: 28, pronoun: 'he' } ]; ``` -------------------------------- ### Function Unrolling Examples Source: https://github.com/origamitower/folktale/blob/master/docs/api/v2.3.0/en/folktale.core.lambda.curry.curry.html Demonstrates how curried functions can be invoked with varying argument patterns. ```javascript subtract(1)(2) === subtract(1, 2) === 1 - 2; ``` ```javascript flip(subtract)(1)(2) === flip(subtract, 1)(2) === flip(subtract, 1, 2) === subtract(2, 1) === 2 - 1; ``` -------------------------------- ### Composition Example: showNames Source: https://github.com/origamitower/folktale/blob/master/docs/api/v2.3.0/en/folktale.core.lambda.compose.compose.html Demonstrates how to use the compose function to create a function that transforms an array of names into a comma-separated string of uppercase names. ```APIDOC ## showNames Composition Example ### Description This example shows how to use `compose` to create a `showNames` function that takes an array of names, converts them to uppercase, and then joins them into a comma-separated string. ### Method N/A (This is a function composition example, not an HTTP endpoint) ### Endpoint N/A ### Parameters None ### Request Example ```javascript const compose = require('folktale/core/lambda/compose'); const upcase = (name) => name.toUpperCase(); const map = (transform, items) => items.map(transform); const join = (separator, items) => items.join(separator); const showNames = compose( capitals => join(', ', capitals), names => map(upcase, names) ); const names = [ 'Alissa', 'Max', 'Talib' ]; showNames(names); // ==> 'ALISSA, MAX, TALIB' ``` ### Response #### Success Response Returns a string with names transformed and joined. #### Response Example ```json { "result": "ALISSA, MAX, TALIB" } ``` ``` -------------------------------- ### Define Executable Markdown Examples Source: https://github.com/origamitower/folktale/blob/master/docs/_docs/v2.3.0/contributing/documentation.md Prefix a Markdown code block with a paragraph or heading ending in double colons to mark it for execution. ```md ## Example:: // this JS will be executed. A paragraph: // This JS will not be executed. Another paragraph:: // But this one will. ``` -------------------------------- ### Run Folktale Task as a Promise Source: https://github.com/origamitower/folktale/blob/master/annotations/source/en/concurrency/task/task-execution/promise.md Use the `.promise()` method on a task's execution to get its eventual value as a JavaScript Promise. This example demonstrates resolving a task with a value, rejecting a task with a value, and cancelling a task. ```javascript const { task, of, rejected } = require('folktale/concurrency/task'); const result1 = await of(1).run().promise(); $ASSERT(result1 == 1); try { const result2 = await rejected(1).run().promise(); throw 'never happens'; } catch (error) { $ASSERT(error == 1); } try { const result3 = await task(r => r.cancel()).run().promise(); throw 'never happens'; } catch (error) { const { Cancelled } = require('folktale/concurrency/future/_execution-state'); $ASSERT(Cancelled.hasInstance(error)); } ``` -------------------------------- ### Compile Application with Browserify Source: https://github.com/origamitower/folktale/wiki/Installing-Folktale Use the Browserify command-line tool to bundle your entry-point JavaScript file into a single file for the browser. This command is run from your project's root. ```bash ./node_modules/.bin/browserify index.js > my-app.js ``` -------------------------------- ### Running Tasks (Legacy vs. New) Source: https://github.com/origamitower/folktale/blob/master/docs/_docs/v2.3.0/migrating/from-data.task.md Comparison of manual resource management via .fork() versus automatic management via TaskExecution. ```javascript const Task = require('data.task'); function delay(ms) { return new Task((reject, resolve) => { return setTimeout( () => { resolve() }, ms ); }, (timer) => { clearTimeout(timer); }); } const delayTask = delay(1000); const resources = delayTask.fork( (error) => { delayTask.cleanup(resources); }, (value) => { delayTask.cleanup(resources); } ); ``` ```javascript const { task } = require('folktale/concurrency/task'); function delay(ms) { return task(resolver => { const timerId = setTimeout( () => { resolver.resolve() }, ms ); resolver.cleanup(() => { clearTimeout(timerId); }); }); } delay(100).run(); ``` -------------------------------- ### Deprecated get method Source: https://github.com/origamitower/folktale/blob/master/annotations/source/en/result/get.md Documentation for the deprecated get method in folktale.result.Ok and folktale.result.Error. ```APIDOC ## GET folktale.result.Ok.prototype.get / folktale.result.Error.prototype.get ### Description Retrieves the value contained within the Result type. This method is deprecated as of version 2.0.0. ### Method GET ### Parameters None ### Deprecation Notice - **Version**: 2.0.0 - **Replaced By**: unsafeGet() - **Reason**: We want to discourage the use of partial functions, and having short names makes it easy for people to want to use them without thinking about the problems. For more details see https://github.com/origamitower/folktale/issues/42 ``` -------------------------------- ### Compile with Browserify Source: https://github.com/origamitower/folktale/blob/master/docs/_docs/v2.3.0/download.md Use the Browserify command-line tool to compile your entry-point JavaScript file into a single bundle. This command should be run from your project's root directory. ```bash $ ./node_modules/.bin/browserify index.js > my-app.js ``` -------------------------------- ### Run a task Source: https://github.com/origamitower/folktale/blob/master/annotations/source/en/concurrency/task/index.md Demonstrates the basic execution of a task using the run method. ```javascript const { task } = require('folktale/concurrency/task'); const hello = task(resolver => resolver.resolve('hello')); const helloExecution = hello.run(); ``` -------------------------------- ### Execute a Task using run Source: https://github.com/origamitower/folktale/blob/master/annotations/source/en/concurrency/task/task/run.md Demonstrates how to trigger a task execution and verify state changes using a promise. ```javascript const { task } = require('folktale/concurrency/task'); let message = ''; const sayHello = task(resolver => { message = 'hello'; resolver.resolve(); }); $ASSERT(message == ''); await sayHello.run().promise(); $ASSERT(message == 'hello'); ``` -------------------------------- ### Create tasks from values Source: https://github.com/origamitower/folktale/blob/master/annotations/source/en/concurrency/task/index.md Shows how to create tasks that resolve immediately using the task constructor or the of and rejected helpers. ```javascript const one = task(resolver => resolver.resolve(1)); ``` ```javascript const { of, rejected } = require('folktale/concurrency/task'); const one_ = of(1); const two_ = rejected(2); ``` -------------------------------- ### Deprecated get() method implementation Source: https://github.com/origamitower/folktale/blob/master/docs/api/v2.3.0/en/folktale.maybe.maybe.get.html The original implementation of the get() method which triggers a deprecation warning and delegates to unsafeGet(). ```javascript 'get'() { warnDeprecation('`.get()` is deprecated, and has been renamed to `.unsafeGet()`.'); return this.unsafeGet(); } ``` -------------------------------- ### Manage asynchronous tasks with Task Source: https://context7.com/origamitower/folktale/llms.txt Demonstrates creating, running, cancelling, mapping, chaining, and combining tasks. ```javascript const { task } = require('folktale/concurrency/task'); const Task = require('folktale/concurrency/task'); // Creating a Task const delayedValue = task(resolver => { const timer = setTimeout(() => resolver.resolve(42), 1000); resolver.cleanup(() => clearTimeout(timer)); resolver.onCancelled(() => clearTimeout(timer)); }); // Tasks are lazy - nothing happens until run() const execution = delayedValue.run(); // Listen to results execution.listen({ onResolved: value => console.log('Got:', value), onRejected: error => console.log('Error:', error), onCancelled: () => console.log('Cancelled') }); // Cancel a running task execution.cancel(); // Creating resolved/rejected tasks const resolved = Task.of(42); const rejected = Task.rejected('error'); // Mapping over tasks const doubled = Task.of(21).map(x => x * 2); doubled.run().listen({ onResolved: v => console.log(v) // => 42 }); // Chaining async operations const fetchUser = (id) => task(resolver => { setTimeout(() => resolver.resolve({ id, name: 'John' }), 100); }); const fetchPosts = (user) => task(resolver => { setTimeout(() => resolver.resolve([ { userId: user.id, title: 'Post 1' }, { userId: user.id, title: 'Post 2' } ]), 100); }); fetchUser(1) .chain(user => fetchPosts(user)) .map(posts => posts.length) .run() .listen({ onResolved: count => console.log(`User has ${count} posts`) }); // Error handling with orElse const failingTask = Task.rejected('network error'); const withFallback = failingTask.orElse(err => Task.of('cached data')); withFallback.run().listen({ onResolved: v => console.log(v) // => 'cached data' }); // Running tasks in parallel with and const task1 = Task.of('a'); const task2 = Task.of('b'); task1.and(task2).run().listen({ onResolved: ([a, b]) => console.log(a, b) // => 'a' 'b' }); // Racing tasks with or const slow = task(r => setTimeout(() => r.resolve('slow'), 1000)); const fast = task(r => setTimeout(() => r.resolve('fast'), 100)); slow.or(fast).run().listen({ onResolved: v => console.log(v) // => 'fast' }); ``` -------------------------------- ### Instance Methods Source: https://github.com/origamitower/folktale/blob/master/docs/api/v2.3.0/en/folktale.result.result.1.html Common instance methods available on Ok variants. ```APIDOC ## Instance Methods ### concat(other) Combines two Results such that if they're both successful (Ok) their values are concatenated. Otherwise returns the failure. ### equals(value) Performs a deep-comparison of two Result values for equality. ### getOrElse(default) Extracts the value of a Result structure if it is an Ok, otherwise returns the provided default value. ### merge() Returns the value inside of the Result structure, regardless of its state. ### toMaybe() Transforms a Result into a Maybe. Error values are lost in the process. ``` -------------------------------- ### Fantasy Land Applicative Instance Source: https://github.com/origamitower/folktale/blob/master/docs/api/v2.3.0/en/folktale.maybe.maybe.0.html Documentation for the Applicative instance methods in Fantasy Land, including `ap` for both 1.x and 2.x+ versions. ```APIDOC ## Fantasy Land Applicative Instance ### Description Provides methods for the Applicative Functor pattern as defined by the Fantasy Land specification. ### Methods #### `ap(that)` Part of the Applicative instance for Fantasy Land 1.x. See the `apply` method for details. #### `fantasy-land/ap(that)` Part of the Applicative instance for Fantasy Land 2.x+. See the `apply` method for details. #### `fantasy-land/of(value)` Part of the Applicative instance for Fantasy Land 2.x+. See the `of` method for details. ``` -------------------------------- ### Usage of waitAll Source: https://github.com/origamitower/folktale/blob/master/docs/api/v2.3.0/en/folktale.concurrency.task.wait-all.waitall.html Demonstrates how to combine multiple tasks using waitAll and execute them as a promise. ```javascript const { of, waitAll } = require('folktale/concurrency/task'); const result = await waitAll([ of(1), of(2), of(3) ]).run().promise(); $ASSERT(result == [1, 2, 3]); ``` -------------------------------- ### Get Textual Representation of State Source: https://github.com/origamitower/folktale/blob/master/docs/api/v2.3.0/en/folktale.concurrency.future._execution-state.inspect-1.html Use the experimental toString() method to get a textual representation of the current state. This API is experimental and may change or be removed in future versions. ```javascript () => variantName ``` -------------------------------- ### Compile and test changes Source: https://github.com/origamitower/folktale/blob/master/docs/_docs/v2.3.0/contributing/new-features.md Compile the project and verify functionality using the Node.js REPL. ```bash $ ./node_modules/.bin/furipota run compile ``` ```javascript >> var folktale = require('.'); >> folktale.core.lambda.identity('hello'); 'hello' ``` -------------------------------- ### Example Bug Report: `constant` throws error with `Array.map` Source: https://github.com/origamitower/folktale/blob/master/docs/_docs/support/bugs.md This example demonstrates a bug where the `constant` function from Folktale throws a TypeError when used with `Array.map`. It includes steps to reproduce, expected behavior, observed behavior, and environment details. ```javascript const constant = require('folktale/core/lambda/constant'); [1, 2, 3].map(constant(0)); // => Uncaught TypeError: 0 is not a function ``` -------------------------------- ### Special values: get constructor Source: https://github.com/origamitower/folktale/blob/master/docs/api/v2.3.0/en/folktale.result.result.1.html Retrieves the constructor for this variant. ```APIDOC ## Special values: get constructor ### Description The constructor for this variant. ### Method `constructor` ``` -------------------------------- ### Special values: get constructor Source: https://github.com/origamitower/folktale/blob/master/docs/api/v2.3.0/en/folktale.maybe.maybe.just.html The constructor function for this variant. ```APIDOC ## get constructor ### Description The constructor function for this variant. ### Endpoint `folktale.adt.union.union.constructor-4` ``` -------------------------------- ### GET tag Source: https://github.com/origamitower/folktale/blob/master/docs/api/v2.3.0/en/-unknown-module-.folktale.concurrency.future._executionstate.variants.0.tag.html Retrieves the internal tag of a union variant. ```APIDOC ## GET tag ### Description Retrieves the internal tag of the variant. Note that this feature is experimental and may change or be removed in future versions. ### Signature get tag() ### Source Code Defined in source/adt/union/union.js at line 128, column 25 ```javascript get tag() { return name; } ``` ``` -------------------------------- ### Sequencing Tasks with Chain Source: https://github.com/origamitower/folktale/blob/master/annotations/source/en/concurrency/task/task/chain.md Demonstrates how to use the `chain` method to sequence successful Task resolutions and handle rejected Tasks. The transformation only occurs if the initial Task resolves. ```javascript const { of, rejected } = require('folktale/concurrency/task'); const helloWorld = of('hello').chain(v => of(v + ' world')); const result1 = await helloWorld.run().promise(); $ASSERT(result1 == 'hello world'); const world = of('hello').chain(v => rejected('world')); try { const result2 = await world.run().promise(); throw 'never happens'; } catch (error) { $ASSERT(error == 'world'); } const hello = rejected('hello').chain(v => of('world')); try { const result3 = await hello.run().promise(); throw 'never happens'; } catch (error) { $ASSERT(error == 'hello'); } ``` -------------------------------- ### GET tag Source: https://github.com/origamitower/folktale/blob/master/docs/api/v2.3.0/en/-unknown-module-.folktale.concurrency.future._executionstate.variants.0.prototype.cancelled.tag.html Retrieves the internal tag of a union variant. ```APIDOC ## GET tag ### Description Retrieves the internal tag of the variant. Note that this feature is experimental and subject to change or removal. ### Signature get tag() ### Source Code Defined in source/adt/union/union.js at line 128, column 25 ### Stability experimental ``` -------------------------------- ### Fantasy Land Monad Instance Source: https://github.com/origamitower/folktale/blob/master/docs/api/v2.3.0/en/folktale.maybe.maybe.0.html Documentation for the Monad instance methods in Fantasy Land, specifically `chain`. ```APIDOC ## Fantasy Land Monad Instance ### Description Provides methods for the Monad Functor pattern as defined by the Fantasy Land specification. ### Methods #### `fantasy-land/chain(transformation)` Part of the Monad instance for Fantasy Land 2.x+. See the `chain` method for details. ``` -------------------------------- ### GET type Source: https://github.com/origamitower/folktale/blob/master/docs/api/v2.3.0/en/-unknown-module-.folktale.concurrency.future._executionstate.variants.0.prototype.cancelled.prototype.rejected.type.html Retrieves the internal type identifier of a variant. ```APIDOC ## GET type ### Description Returns the internal type identifier of the variant. Note that this feature is experimental and subject to change. ### Signature get type() ### Source Code Defined in source/adt/union/union.js at line 128, column 25 ```javascript get type() { return typeId; } ``` ``` -------------------------------- ### GET constructor Source: https://github.com/origamitower/folktale/blob/master/docs/api/v2.3.0/en/folktale.adt.union.union.constructor-3.html Retrieves the internal constructor for a variant in a Folktale union. ```APIDOC ## GET constructor ### Description Returns the internal constructor for the variant. ### Method GET ### Endpoint variant.constructor ### Response - **InternalConstructor** (Object) - The internal constructor function for the variant. ``` -------------------------------- ### Standard array method chaining Source: https://github.com/origamitower/folktale/blob/master/annotations/source/en/core/lambda/compose.md Demonstrates standard JavaScript method chaining using map and join. ```javascript const names = [ 'Alissa', 'Max', 'Talib' ]; const upcase = (name) => name.toUpperCase(); names.map(upcase).join(', '); // ==> 'ALISSA, MAX, TALIB' ``` -------------------------------- ### GET type property Source: https://github.com/origamitower/folktale/blob/master/docs/api/v2.3.0/en/-unknown-module-.folktale.concurrency.future._executionstate.variants.0.prototype.cancelled.type.html Retrieves the internal type identifier of a variant. ```APIDOC ## GET type ### Description Retrieves the internal type of the variant. Note that this feature is experimental and subject to change. ### Signature get type() ### Source Code Defined in source/adt/union/union.js at line 128, column 25 ```javascript get type() { return typeId; } ``` ### Stability Experimental ``` -------------------------------- ### Fantasy Land Semigroup and Monoid Instances Source: https://github.com/origamitower/folktale/blob/master/docs/api/v2.3.0/en/folktale.maybe.maybe.0.html Documentation for Semigroup and Monoid instance methods in Fantasy Land, including `concat` and `empty`. ```APIDOC ## Fantasy Land Semigroup and Monoid Instances ### Description Provides methods for the Semigroup and Monoid patterns as defined by the Fantasy Land specification. ### Methods #### `fantasy-land/concat(that)` Part of the Semigroup instance for Fantasy Land 2.x+. See the `concat` method for details. #### `fantasy-land/empty()` Part of the Monoid instance for Fantasy Land 2.x+. See the `empty` method for details. ``` -------------------------------- ### Fantasy Land Applicative Instance (1.x) Source: https://github.com/origamitower/folktale/blob/master/docs/api/v2.3.0/en/folktale.result.result.1.html Details the `ap` method for the Applicative instance compatible with Fantasy Land 1.x. ```APIDOC ## Fantasy Land Applicative Instance (1.x) ### Description Part of the Applicative instance for Fantasy Land 1.x. See the `apply` method for details. ### Method `ap` ``` -------------------------------- ### Future State Access Source: https://github.com/origamitower/folktale/blob/master/docs/api/v2.3.0/en/folktale.concurrency.future._future._state.html Provides information on how to get the current state of a Future. ```APIDOC ## GET /future/state ### Description Retrieves the current execution state of a Future object. ### Method GET ### Endpoint /future/state ### Parameters #### Path Parameters None #### Query Parameters None ### Request Body None ### Request Example None ### Response #### Success Response (200) - **state** (ExecutionState) - The current state of the Future. #### Response Example ```json { "state": "pending" } ``` ### Error Handling - **404**: Future not found. - **500**: Internal server error. ``` -------------------------------- ### Listening to Task Results (Legacy vs. New) Source: https://github.com/origamitower/folktale/blob/master/docs/_docs/v2.3.0/migrating/from-data.task.md Comparison of the .fork() method and the .run().listen() pattern for handling task outcomes. ```javascript const Task = require('data.task'); const one = new Task((reject, resolve) => resolve(1)); one.fork( (error) => { console.log('something went wrong') }, (value) => { console.log(`The value is ${value}`) } ); // logs "The value is 1" ``` ```javascript const { task } = require('folktale/concurrency/task'); const one = task(resolver => resolver.resolve(1)); one.run().listen({ onCancelled: () => { console.log('the task was cancelled') }, onRejected: (error) => { console.log('something went wrong') }, onResolved: (value) => { console.log(`The value is ${value}`) } }); // logs "The value is 1" ``` -------------------------------- ### GET tag Source: https://github.com/origamitower/folktale/blob/master/docs/api/v2.3.0/en/-unknown-module-.folktale.result.error.tag.html Retrieves the unique tag identifier for a variant in a Result union. ```APIDOC ## GET tag ### Description Returns the unique tag for the current variant within a Result union. ### Method GET ### Endpoint tag ### Response - **tag** (string) - The unique identifier for the variant. ``` -------------------------------- ### GET constructor Source: https://github.com/origamitower/folktale/blob/master/docs/api/v2.3.0/en/-unknown-module-.folktale.maybe.just.constructor.html Retrieves the constructor function for a specific variant in a union type. ```APIDOC ## GET constructor ### Description The constructor property returns the internal constructor function for a given variant. ### Signature get constructor() ### Source Code Defined in source/adt/union/union.js at line 128, column 25 ### Stability stable ``` -------------------------------- ### Run project tests and linting Source: https://github.com/origamitower/folktale/blob/master/docs/_docs/v2.3.0/contributing/bugfixes.md Commands to ensure all tests pass and code conforms to project style guidelines before submission. ```bash $ ./node_modules/.bin/furipota run test ``` ```bash $ ./node_modules/.bin/furipota run lint ``` -------------------------------- ### Currying Nested Functions Source: https://github.com/origamitower/folktale/blob/master/docs/api/v2.3.0/en/folktale.core.lambda.curry.curry.html Example of wrapping curried functions with the curry utility. ```javascript const subtract = curry(2, (x, y) => x - y); const flip = curry(3, (f, x, y) => f(y, x)); ``` -------------------------------- ### Task Instance Methods Source: https://github.com/origamitower/folktale/blob/master/docs/api/v2.3.0/en/-unknown-module-.folktale.concurrency.task._task.prototype.html Overview of the instance methods available for the Task structure, including transformation, execution, and error recovery. ```APIDOC ## Task Instance Methods ### Description Methods for manipulating and executing Task structures which model asynchronous processes. ### Methods - **and(that)**: Constructs a new task that awaits both tasks to resolve. - **or(that)**: Combines two tasks, assimilating the result of the first one to resolve. - **run()**: Executes a Task and returns a TaskExecution object. - **apply(task)**: Applies the function in the left task to the value on the right task. - **bimap(rejectionTransformation, successTransformation)**: Transforms the rejected or resolved values of a Task. - **chain(transformation)**: Transforms the value and state of a Task. - **map(transformation)**: Transforms the value of a successful task. - **mapRejected(transformation)**: Transforms the value of a failed task. - **orElse(handler)**: Transforms a failed task's value and state. - **swap()**: Inverts the state of a Task (success to failure, failure to success). - **willMatchWith(pattern)**: Chooses and executes a function for each variant in a Task. ``` -------------------------------- ### GET Result.value Source: https://github.com/origamitower/folktale/blob/master/docs/api/v2.3.0/en/folktale.result.result.value.html Accesses the value stored inside an Error instance of a Result object. ```APIDOC ## GET Result.value ### Description Retrieves the value contained in an Error instance of the Result structure. This is typically used to destructure the instance during a .matchWith call. ### Signature get value() => a ### Request Example const Result = require('folktale/result'); Result.Error(1).matchWith({ Error: ({ value }) => value, Ok: ({ value }) => 'nothing' }); // ==> 1 ### Source Code Defined in source/result/result.js at line 48, column 24 ``` -------------------------------- ### GET constructor Source: https://github.com/origamitower/folktale/blob/master/docs/api/v2.3.0/en/folktale.adt.union.union.constructor-8.html Retrieves the internal constructor for a specific variant within an ADT union. ```APIDOC ## GET constructor ### Description The constructor property returns the internal constructor function for the variant. ### Endpoint folktale/adt/union/union ### Response - **InternalConstructor** (Function) - The internal constructor function for the variant. ``` -------------------------------- ### Promise Interoperability Source: https://github.com/origamitower/folktale/blob/master/docs/_docs/v2.3.0/migrating/from-data.task.md Illustrates converting between Tasks and Promises using legacy methods and the new native TaskExecution and fromPromised utilities. ```js const Task = require('data.task'); const Async = require('control.async')(Task); Async.fromPromise(Promise.resolve(1)); Async.toPromise(Task.of(1)); ``` ```js const { of } = require('folktale/concurrency/task'); of(1).run().promise(); ``` ```js const { fromPromised } = require('folktale/concurrency/task'); const p = (x) => Promise.resolve(x); fromPromised(p)(1); // ==> task.of(1) ``` -------------------------------- ### GET tag property Source: https://github.com/origamitower/folktale/blob/master/docs/api/v2.3.0/en/-unknown-module-.folktale.maybe.just.prototype.variants.0.tag.html Retrieves the unique tag identifier for the current Maybe variant. ```APIDOC ## GET tag ### Description Returns the unique tag for the current variant, which is used to distinguish between different Maybe variants. ### Method GET ### Endpoint get tag() ### Response - **tag** (string) - The unique identifier for the variant. ``` -------------------------------- ### GET type property Source: https://github.com/origamitower/folktale/blob/master/docs/api/v2.3.0/en/-unknown-module-.folktale.maybe.just.prototype.variants.0.type.html Retrieves the unique type identifier for a variant in a Folktale union. ```APIDOC ## GET type ### Description Returns the unique type identifier for the variant, used for type checking within Folktale data structures. ### Signature get type() ### Source Code Defined in source/adt/union/union.js at line 128, column 25 ```javascript get type() { return typeId; } ``` ### Stability stable ``` -------------------------------- ### Creating a successful task Source: https://github.com/origamitower/folktale/blob/master/docs/api/v2.3.0/en/folktale.concurrency.task.task.task.html Demonstrates a basic task that resolves immediately with a value. ```javascript const hello = task(resolver => resolver.resolve('hello')); const result1 = await hello.run().promise(); $ASSERT(result1 == 'hello'); ``` -------------------------------- ### Task to Future Conversion Source: https://github.com/origamitower/folktale/blob/master/docs/api/v2.3.0/en/-unknown-module-.folktale.concurrency.task._taskexecution.prototype.future.html Demonstrates how to get the eventual value of a Task as a Folktale Future. ```APIDOC ## Task to Future Conversion ### Description Gets the eventual value of a Task as a Folktale `Future`. ### Method N/A (This is a conceptual example of library usage, not a direct API endpoint) ### Endpoint N/A ### Request Example ```javascript const { task, of, rejected } = require('folktale/concurrency/task'); const { Cancelled, Resolved, Rejected } = require('folktale/concurrency/future/_execution-state'); // Example 1: Resolved Task of(1).run().future()._state; // Expected Output: Resolved(1) // Example 2: Rejected Task rejected(1).run().future()._state; // Expected Output: Rejected(1) // Example 3: Cancelled Task task(r => r.cancel()).run().future()._state; // Expected Output: Cancelled() ``` ### Response #### Success Response (Conceptual) - **_state** (Enum: Resolved, Rejected, Cancelled) - The final state of the Future, indicating the outcome of the Task. #### Response Example ```json { "example": "Resolved(1)" } ``` ```json { "example": "Rejected(1)" } ``` ```json { "example": "Cancelled()" } ``` ``` -------------------------------- ### Fantasy Land Monad Instance (2.x+) Source: https://github.com/origamitower/folktale/blob/master/docs/api/v2.3.0/en/folktale.result.result.1.html Details the `chain` method for the Monad instance compatible with Fantasy Land 2.x+. ```APIDOC ## Fantasy Land Monad Instance (2.x+) ### Description Part of the Monad instance for Fantasy Land 2.x+. See the `chain` method for details. ### Method `chain(transformation)` ``` -------------------------------- ### GET /maybe/get Source: https://github.com/origamitower/folktale/blob/master/docs/api/v2.3.0/en/folktale.maybe.maybe.get.html Retrieves the value from a Maybe instance. Note that this method is deprecated and has been renamed to unsafeGet(). ```APIDOC ## GET /maybe/get ### Description Retrieves the value from a Maybe instance. This method is deprecated since version 2.0.0 and has been renamed to `unsafeGet()` to discourage the use of partial functions. ### Method GET ### Signature forall a: (Maybe a).() => a :: (throws TypeError) ### Stability Deprecated ### Source Code Defined in source/maybe/maybe.js at line 288, column 21 ``` -------------------------------- ### GET tag property Source: https://github.com/origamitower/folktale/blob/master/docs/api/v2.3.0/en/-unknown-module-.folktale.result.error.prototype.variants.1.tag.html Retrieves the unique tag identifier for a variant in a Folktale union type. ```APIDOC ## GET tag ### Description The tag property returns a unique identifier for the specific variant within a Result union type. ### Signature get tag() ### Source Code Defined in source/adt/union/union.js at line 128, column 25 ### Stability stable ``` -------------------------------- ### Source implementation of listen Source: https://github.com/origamitower/folktale/blob/master/docs/api/v2.3.0/en/folktale.concurrency.future._future.listen.html The internal implementation of the listen method, showing how it interacts with the Future's state and listener queue. ```javascript listen(pattern) { this._state.matchWith({ Pending: () => this._listeners.push(pattern), Cancelled: () => pattern.onCancelled(), Resolved: ({ value }) => pattern.onResolved(value), Rejected: ({ reason }) => pattern.onRejected(reason) }); return this; } ``` -------------------------------- ### Constructing a Task (Legacy vs. New) Source: https://github.com/origamitower/folktale/blob/master/docs/_docs/v2.3.0/migrating/from-data.task.md Comparison of the old constructor-based Task creation and the new functional task approach. ```javascript const Task = require('data.task'); function delay(ms) { return new Task((reject, resolve) => { return setTimeout( () => { resolve() }, ms ); }, (timer) => { clearTimeout(timer); }); } ``` ```javascript const { task } = require('folktale/concurrency/task'); function delay(ms) { return task(resolver => { const timerId = setTimeout( () => { resolver.resolve() }, ms ); resolver.cleanup(() => { clearTimeout(timerId); }); }); } ``` -------------------------------- ### GET constructor Source: https://github.com/origamitower/folktale/blob/master/docs/api/v2.3.0/en/-unknown-module-.folktale.concurrency.future._executionstate.variants.0.prototype.cancelled.constructor.html Retrieves the constructor for the variant. Note that this feature is currently experimental and subject to change. ```APIDOC ## GET constructor ### Description Retrieves the constructor for the variant. This feature is marked as experimental and should not be used in production applications. ### Method GET ### Endpoint constructor() ### Response - **InternalConstructor** (Object) - The internal constructor function for the variant. ``` -------------------------------- ### Fantasy Land Infix API - Convenience Methods Source: https://github.com/origamitower/folktale/blob/master/docs/api/v2.3.0/en/folktale.fantasy-land.infix.html This section describes the experimental convenience methods available for Fantasy Land compliance using the infix syntax. ```APIDOC ## apply: infix(applicativeValue) ### Description Applies the function inside an applicative to the value of another applicative. ### Method Not applicable (infix function) ### Endpoint Not applicable (infix function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) Not applicable (infix function) #### Response Example None ``` ```APIDOC ## bimap: infix(transformLeft, transformRight) ### Description Maps one function over each side of a Bifunctor. ### Method Not applicable (infix function) ### Endpoint Not applicable (infix function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) Not applicable (infix function) #### Response Example None ``` ```APIDOC ## chain: infix(transformation) ### Description Transforms a monad with an unary function. ### Method Not applicable (infix function) ### Endpoint Not applicable (infix function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) Not applicable (infix function) #### Response Example None ``` ```APIDOC ## concat: infix(aSemigroup) ### Description Joins two semigroups. ### Method Not applicable (infix function) ### Endpoint Not applicable (infix function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) Not applicable (infix function) #### Response Example None ``` ```APIDOC ## empty: infix() ### Description Returns the identity object for a monoid. ### Method Not applicable (infix function) ### Endpoint Not applicable (infix function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) Not applicable (infix function) #### Response Example None ``` ```APIDOC ## equals: infix(aSetoid) ### Description Compares two setoids for equality. ### Method Not applicable (infix function) ### Endpoint Not applicable (infix function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) Not applicable (infix function) #### Response Example None ``` ```APIDOC ## map: infix(transformation) ### Description Transforms the contents of a Functor. ### Method Not applicable (infix function) ### Endpoint Not applicable (infix function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) Not applicable (infix function) #### Response Example None ``` ```APIDOC ## of: infix(value) ### Description Constructs an applicative containing the given value. ### Method Not applicable (infix function) ### Endpoint Not applicable (infix function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) Not applicable (infix function) #### Response Example None ``` -------------------------------- ### Map to extract age and pronoun Source: https://github.com/origamitower/folktale/blob/master/docs/api/v2.3.0/en/folktale.core.lambda.curry.curry.html Examples of extracting different properties using the same mapping pattern. ```javascript people.map(person => person.age); // ==> [26, 19, 28] people.map(person => person.pronoun); // ==> ['she', 'they', 'he'] ``` -------------------------------- ### Constructing Maybe values (Previous) Source: https://github.com/origamitower/folktale/blob/master/docs/_docs/v2.3.0/migrating/from-data.maybe.md Demonstrates the previous way of importing and constructing Maybe values using `data.maybe`. ```javascript const Maybe = require('data.maybe'); Maybe.Just(1); Maybe.Nothing(); ``` -------------------------------- ### GET /validation/get Source: https://github.com/origamitower/folktale/blob/master/docs/api/v2.3.0/en/folktale.validation.validation.get.html Retrieves the value from a Validation object. Note that this method is deprecated since version 2.0.0. ```APIDOC ## GET get() ### Description Retrieves the value from a Validation object. This method has been renamed to `unsafeGet()` to discourage the use of partial functions. ### Method GET ### Signature forall a, b: (Validation a b).() => b :: throws TypeError ### Stability Deprecated ### Module folktale/validation/validation ``` -------------------------------- ### Fantasy Land Setoid Instance (2.x+) Source: https://github.com/origamitower/folktale/blob/master/docs/api/v2.3.0/en/folktale.result.result.1.html Details the `equals` method for the Setoid instance compatible with Fantasy Land 2.x+. ```APIDOC ## Fantasy Land Setoid Instance (2.x+) ### Description Part of the Setoid instance for Fantasy Land 2.x+. See the `equals` method for details. ### Method `equals(that)` ``` -------------------------------- ### Fantasy Land Applicative Instance (2.x+) Source: https://github.com/origamitower/folktale/blob/master/docs/api/v2.3.0/en/folktale.result.result.1.html Details the `ap` method for the Applicative instance compatible with Fantasy Land 2.x+. ```APIDOC ## Fantasy Land Applicative Instance (2.x+) ### Description Part of the Applicative instance for Fantasy Land 2.x+. See the `apply` method for details. ### Method `ap` ``` -------------------------------- ### Get Tag of Union Variant Source: https://github.com/origamitower/folktale/blob/master/docs/api/v2.3.0/en/-unknown-module-.folktale.concurrency.future._executionstate.variants.0.prototype.cancelled.prototype.rejected.prototype.resolved.tag.html Retrieves the internal tag of a union variant. This API is experimental and may change. ```javascript get tag() { return name; } ``` -------------------------------- ### Scope Variables in Executable Examples Source: https://github.com/origamitower/folktale/blob/master/docs/_docs/v2.3.0/contributing/documentation.md Variables defined in code blocks under the same heading are shared across subsequent blocks. ```md # Heading 1:: const x = 1; Another paragraph:: x + 1; // 2 # Heading 2:: x + 1; // Error: `x` is not defined ``` -------------------------------- ### Import Core Object Utilities Source: https://github.com/origamitower/folktale/blob/master/docs/api/v2.3.0/en/folktale.core.object.html Imports all core object utilities for use in your project. Ensure these utilities are available in your environment. ```javascript { mapEntries: require('./map-entries'), mapValues: require('./map-values'), values: require('./values'), toPairs: require('./to-pairs'), fromPairs: require('./from-pairs') } ``` -------------------------------- ### Use Folktale in Node.js Source: https://github.com/origamitower/folktale/wiki/Installing-Folktale In Node.js environments, import Folktale using require. This example demonstrates the identity function. ```javascript const folktale = require('folktale'); folktale.core.lambda.identity(1); // ==> 1 ``` -------------------------------- ### Maybe Instance Methods Source: https://github.com/origamitower/folktale/blob/master/docs/api/v2.3.0/en/folktale.maybe.maybe.0.html Provides documentation for instance methods available on Maybe values. ```APIDOC ## Maybe Instance Methods ### Description These are methods available on instances of the Maybe type, allowing for manipulation and inspection of Maybe values. ### Method Instance Methods ### Endpoint N/A ### Parameters Parameters vary by method. See individual method documentation. ### Request Example N/A ### Response Responses vary by method. #### Instance Methods Documentation: ##### `concat(otherMaybe)` - **Description**: Combines two maybes such that if they both have values (are a `Just`) their values are concatenated. Maybe values are expected to be Fantasy Land 1.x semigroups and implement a `concat` method. - **Type**: `(otherMaybe: Maybe) => Maybe` ##### `equals(value)` - **Description**: Performs a deep-comparison of two Maybe values for equality. - **Type**: `(value: Maybe) => boolean` ##### `getOrElse(defaultValue)` - **Description**: Extracts the value of a Maybe structure, if it exists (i.e.: is a `Just`), otherwise returns the provided default value. - **Type**: `(defaultValue: T) => T` ##### `unsafeGet()` - **Description**: Extracts the value from a `Just` structure. Throws an error if called on `Nothing`. - **Type**: `() => T` ##### `toResult(fallbackValue)` - **Description**: A convenience method for the `folktale/conversions/maybe-to-result` module. Converts a Maybe to a Result type. - **Type**: `(fallbackValue: E) => Result` ##### `toValidation(fallbackValue)` - **Description**: A convenience method for the `folktale/conversions/maybe-to-validation` module. Converts a Maybe to a Validation type. - **Type**: `(fallbackValue: E) => Validation` ##### `inspect()` or `toString()` - **Description**: A textual representation for Maybe instances. - **Type**: `() => string` ##### `isNothing` (getter) - **Description**: True if the value is a `Nothing` instance. - **Type**: `boolean` ##### `empty()` - **Description**: Constructs a Maybe containing no value (a `Nothing`). This is an inherited method. - **Type**: `() => Maybe` ##### `of(value)` - **Description**: Constructs a Maybe value that represents a successful value (a `Just`). This is an inherited method. - **Type**: `(value: T) => Maybe` ``` -------------------------------- ### WebPack Configuration File Source: https://github.com/origamitower/folktale/wiki/Installing-Folktale Create a webpack.config.js file in your project's root to define how WebPack should build your application, specifying the entry point and output filename. ```javascript module.exports = { entry: './index.js', output: { filename: 'my-app.js' } }; ``` -------------------------------- ### Define entity metadata in JavaScript Source: https://github.com/origamitower/folktale/blob/master/docs/_docs/v2.3.0/contributing/documentation.md Use multi-line comments starting with ~ to define stability, type, and complexity metadata for functions. ```javascript /*~ * stability: stable * type: | * forall a. (a) => a */ const identity = (a) => a; ``` ```javascript /*~ * stability: stable */ ``` ```javascript /*~ * type: | * (String) => String */ ``` ```javascript /*~ * complexity: O(array.length) */ ``` -------------------------------- ### Get Variant Type Source: https://github.com/origamitower/folktale/blob/master/docs/api/v2.3.0/en/-unknown-module-.folktale.maybe.just.prototype.variants.0.type.html Accesses the unique type identifier for a variant. This is used for type checking within Folktale data structures. ```javascript get type() { return typeId; } ``` -------------------------------- ### Manual currying implementation Source: https://github.com/origamitower/folktale/blob/master/annotations/source/en/core/lambda/curry.md Demonstrates the manual transformation of a function into a curried form. ```javascript const property2 = (key) => (object) => object[key]; const greeting2 = property2('greeting'); greeting({ greeting: 'Hi' }); ``` -------------------------------- ### Manual partial application Source: https://github.com/origamitower/folktale/blob/master/annotations/source/en/core/lambda/curry.md Creating a specialized function manually without using currying utilities. ```javascript const greeting = (object) => property(object, 'greeting'); greeting({ greeting: 'Hi' }); // ==> 'Hi' ``` -------------------------------- ### Get Constructor Property Source: https://github.com/origamitower/folktale/blob/master/docs/api/v2.3.0/en/-unknown-module-.folktale.concurrency.future._executionstate.variants.0.constructor.html This experimental getter returns the internal constructor for a union variant. Use with caution as the API may change. ```javascript get constructor() { return InternalConstructor; } ``` -------------------------------- ### Constructing a Task with of Source: https://github.com/origamitower/folktale/blob/master/docs/api/v2.3.0/en/folktale.concurrency.task._task.of.html Demonstrates how to import and use the of function to create a resolved Task. ```javascript const { of } = require('folktale/concurrency/task'); const result = await of('hello').run().promise(); $ASSERT(result == 'hello'); ``` -------------------------------- ### Verify compiled code in Node.js REPL Source: https://github.com/origamitower/folktale/blob/master/docs/_docs/v2.3.0/contributing/bugfixes.md Example of requiring the compiled Folktale library and using a function within the Node.js REPL. ```javascript >> var folktale = require('.'); >> folktale.core.lambda.identity('hello'); 'hello' ``` -------------------------------- ### Convert Deferred to Promise Source: https://github.com/origamitower/folktale/blob/master/docs/api/v2.3.0/en/folktale.concurrency.future._deferred.promise.html Use this method to get the value of a deferred as a Promise. Cancellations on the deferred are mapped to a rejected promise with a special object. ```javascript promise() { return new Promise((resolve, reject) => { this.listen({ onCancelled: _ => reject(Cancelled()), onResolved: resolve, onRejected: reject }); }); } ``` -------------------------------- ### Apply syntax highlighting to documentation Source: https://github.com/origamitower/folktale/blob/master/docs/api/v2.3.0/en/-unknown-module-.folktale.concurrency.future._executionstate.inspect.html A utility script to apply language classes to documentation code blocks. ```javascript void function() { var xs = document.querySelectorAll('.documentation pre code'); for (var i = 0; i < xs.length; ++i) { xs[i].className = 'language-javascript code-block'; } }() ```