Fluture | : butterfly : Fantasy Land compliant | Reactive Programming library
kandi X-RAY | Fluture Summary
kandi X-RAY | Fluture Summary
Fluture offers a control structure similar to Promises, Tasks, Deferreds, and what-have-you. Let's call them Futures. Much like Promises, Futures represent the value arising from the success or failure of an asynchronous operation (I/O). Though unlike Promises, Futures are lazy and adhere to the monadic interface.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Show a message .
- Creates an Eager instance .
- Creates a Transform Transform .
- Run parallel .
- Consume a resource .
- Wrap an async handler function
- Creates a parallel transformation matrix .
- Draggable drain .
- Creates an instance of an interpreter
- Returns an alt transforming function .
Fluture Key Features
Fluture Examples and Code Snippets
const taskify = require('util.taskify')
const fs = require('fs')
const Task = require('taskorama')
// or
// const Task = require('fluture')
const readFileTask = taskify(Task, fs.readFile)
readFileTask('package.json', 'utf8')
.fork(
err =>
import { reject, resolve, fork } from 'fluture'
import { future } from 'fp-ts-fluture/lib/Future'
import { array } from 'fp-ts/lib/Array'
array
.sequence(future)([resolve(1), reject('oops')])
.pipe(fork(e => console.error('Error:', e))
(c
Community Discussions
Trending Discussions on Fluture
QUESTION
I'm newbye experimenting functional programming in Javascript.
I'm learning and using monads (Reader, State, Fluture ...) to compose my Node apps with pure functions.
But often I feel the need of a data structure, similar to a Monad but where I can chain functions in the middleware.
Think of it as a structure of two function
...ANSWER
Answered 2021-Aug-10 at 21:30If you're wanting to map outputs, that's a covariant functor's map
function.
If you're wanting to map inputs, that's a contravariant functor's contramap
function.
If you're wanting to do a change in the middle, you likely have to roll your own, but that doesn't mean you are forced to specify concrete functions in order. If I wanted to be able to specify h
and i
from your example at the last minute, I would partially apply a function like:
QUESTION
I was reading about Fluture, and one way to consume a Future is to call fork. That is all understandable so far but in documentation it states:
"Generally, one only needs to call fork
in a single place in the entire program".
What does it mean? What if I'm using Futures to fetch some content from Api request, I would probably want to do this multiple times throughout the code each with different resolve functions. All of these Futures would then require their own forks, right?
...ANSWER
Answered 2021-Sep-25 at 15:25It is expected that you build your entire program as a big Future
, composed of smaller futures (like many Api calls chained to each other), and only in your main entrypoint do call fork()
.
QUESTION
I am trying to find a way to convert a Promise to a future using the fluture library to implement functional programming, transform the data using a functional pipeline, then transform back to a promise so I can utilize await/async functionality. This is for an express app and I am using global error handling and I am not seeing how to take advantage of global error handling for endpoints if I catch errors in the future process flow without converting to a promise after the future processing is complete.
- Am I right in thinking this way?
- If so, how can I use the promise utility in the code below to translate back to a promise after the encaseP and subsequent pipeline code is called?
- Is there a better way to utilize the future pipeline while still getting errors to the global error handler?
- Also, if I do convert to a promise will that also give me access to the actual value in the future if I utilize await, I assume so?
Apologies if this is a bad question, I am a newbie to functional programming and fluture and am trying to get my ducks in the proper alignment.
...ANSWER
Answered 2021-Mar-08 at 15:33I believe I have answered this question sufficiently in Gitter. I'll summarize my response below for future reference.
There's a few things I see in your code that I would like to address:
findData
: I recommend already wrapping it right there withencaseP
- as early on as possible. So you'd get(arrayList) => encaseP (Promise.reject) (arrayList)
, which can also be written likeencaseP (Promise.reject)
(because the input argument is simply passed down as-is).- The
total1
function can now callfindData
directly and get back a Future. .pipe (res => res)
: This line actually does nothing. Here you transform res, which is a Future of an Array, into res, which is exactly the same thing. It's important to understand that pipe is just function application: https://stackoverflow.com/a/59985017/1001417.pipe (promise (() => {console.log('do nothing')}) (console.log))
: When you consume a Future, the work actually starts and the consumption returns a cancellation function (or a Promise, in the case ofpromise (future)
). You shouldn't do this inside your functions, but outside of them. I recommend reading the introduction to Fluture, especially the part about "not consuming futures". A guiding rule of thumb is that you should only seefork
(orpromise
or any other consumption function) called at the very "edge" of your program. That's at the point where you cannot possibly pass the Future down any further to a party that'll understand it.
After removing that last line from the total1
function, so that the Future is not consumed, but returned from the function, we can consume the Future where needed. For example, an Express middleware that runs the total1
function and forwards its output to the Response would look something like:
QUESTION
I am new to functional programming and I found the following fluture functional programming example that seems to give a really good example for handling database queries and subsequent data manipulation. The caveat however is that in reading about functional programming concepts, Just/Nothing monads seemed to be the suggested approach for handling null checking. 1) How would that fit into this example and 2) if the findOne rejected, would it stop the subsequent chains from running and immediately go to the fork?
...ANSWER
Answered 2021-Mar-05 at 23:27Actually, Maybe (Nothing | Just) is often not what you want for handling errors because, although it can help you short-circuit subsequent operations and give you a hook to provide a default value, it won't tell you why the computation could not complete.
Either (Left | Right) gives you the same features but also lets you access the context that caused your flow to take the error branch because Left
holds data too, like an error message, which is useful for recovering from errors, logging or displaying useful messages to the user.
Fluture gives you an async Either. Because it's async you can't retrieve the value directly (as you are used to with Promises) but apart from that it behaves the same as Maybe/Either: fork
is the equivalent of fold
. You will get short-circuiting and a lot more (like changing track, mapping over the reject branch, etc.).
There is a good introduction here https://dev.to/avaq/fluture-a-functional-alternative-to-promises-21b
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install Fluture
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page