Comments (12)
Hello,
I haven't used monet since my last contributions, so I'm not really up to date with recent modifications. I do have a few comments, but they are non-technical: rather related to my sense of enhancing/decreasing readability and maintaiability, so by no means hard rules:
forEach
is cool on things that are multi-element collections (lists, NELs, sets, ...), but is rather awful on other monads:Maybe::forEach
makes it IMHO more difficult to read than.cata()
with a default behavior. Same holds true for.some
,.forall
, andcontains
..toArray
,toList
,toSet
- sure, I have no idea why they are not there yet :).to<W>(const: <X>(i: Iterable<X>) => W<X>): W<T>
looks cool, but I can't imagine significant use cases. For containers from other libraries, I'd doFancyContainer(monad.toArray())
and call it a day...mapOver(v: X)
,mapTo
- I have no idea how these should work
For Maybe:
.filterNot
- that single!
hurts you so much? :).orLazy
π- lazy version of orElse π (I always wanted to do
.orElse(() => throw ...)
.orNull
π
I believe EIther.fold
should have signature of (f: A => X, g: B => X) => X
for Either<A, B>
, so it's a catamorphism. And I advocate against aliases in general, naming things is hard.
from monet.js.
I just mean leaving .orElse
strict and creating a new method .orElseLazy
which is lazy :-) I.e. not changing the current behaviour of orElse
.
from monet.js.
Hey guys, just noticed this issue.
I'm glad to see that Either.fold
is already on the list of additions being considered! In fact, the reason I'm here is because I was going to ask about adding a fold
alias for all the cata
methods (I'd totally be willing to do this work myself).
I noticed, however, that Maybe
already has a fold
method with the signature fold(ifNone: B)(ifSome: A => B): B
. This seems to be currently undocumented, so how would you guys feel about changing (or overloading) that to fold(ifNone: () => B, ifSome: A => B): B
?
Given that you're already looking into adding Either.fold
, this would maintain consistency by having Maybe.fold
be an alias for Maybe.cata
just as Either.fold
would be to Either.cata
.
Thoughts?
from monet.js.
@WojciechP - nice to see you here :)
forEach
appeared here due to request from community, see: #67.to()
would be a nice shortcut due to existence ofIterable
s in many other useful libs likeImmutable.JS
. It'll allowm.to(Set)
orm.to(OrderedMap)
mapOver
works for a monad containing a function -- instead of writingm.map(fn => fn(val))
one can justm.mapOver(val)
(but that is just proposition, it's an instance method oflodash
collections)mapTo
(can be found inlodash
andRxJS
) is a shortcut of.map(() => val)
filterNot
(can be found in Scala's Option) is great for such situations likem.filter(val => !isEmpty(val))
-->m.filterNot(isEmpty)
Maybe you have a good idea how to name lazy versions of orSome
and orElse
(without overloading and without breaking backwards compatibility) ?
from monet.js.
Hi guys,
Thanks for your work again @ulfryk. I have a couple of comments:
I like .forEach
but I wonder if it should be on all monads? Does it make sense for the IO
monad? I like it for Either
, List
, NEL
and Maybe
-- that is the iterable monads. I think the same goes for the other methods.
The Either monad should have fold
but I think it is an alias for cata
and not bimap
.
The other Maybe instances look pretty good too, but just to be clear are you suggesting creating .orElseLazy()
method and leaving .orElse
as is?
Thanks again for your work!
from monet.js.
@cwmyers - you are absolutely right about fold
- it's not bimap
;)
I suggest adding lazy versions of orSome
and orElse
. What do you mean by and leaving .orElse as is?
from monet.js.
Yes :D
from monet.js.
hello! great project I would to read the draft but am unable to access it.. would you be so kind? i'm considering an attempt to contribute a continuationMonad to monet - would you consider that worthwhile? or is it already there? (last time i checked is a while ago) thanks, cheers Erik
from monet.js.
@erikschoel - I've checked DRAFT on few browsers (also in incognito windows) and it's available for public readingβ¦
@cwmyers - WDYT about Continuation Monad ?
from monet.js.
@Tbrisbane - actually I (and few my colleagues) use MonetJS
extensively in few projects. And we use .fold(ifNone: B)(ifSome: A=> B): B
. On the other hand overloading it is not possible -- consider situation when we have Maybe[A => B]
- how would JS know that arg passed to fold is not lazy?
from monet.js.
well.. for web development I fell sometimes split into halves:
- running "stuff" as quickly and smoothly as possible all the time
- loading / deferring / await state etc
and subsequently the need to integrate the two as smoothly and going as it were unnoticed to the overall scheme...
i have tried quite a bit to use a "free monads over channels approach" but I feel only fits point 1.
so now I am experimenting an approach with free monads running in the body of continuationMonads - so when they yield because they ran out - but already know there will be more - I want to tie those together using continuationMonads - rather than taking on a channel or listening somewhere - in other words being way too busy when there momentarily is nothing - but equally continue running the free as soon as possible... just thoughts I have no training or educational background in any of this... there is a very very interesting free monad implementation with an amazing example of threads running continuously - but really - interleaved - I still don't like the redundant activity (quite a bit) when there is nothing to do - but when there is they rock - anyway.. tried to locate the repo but cannot - I can send you the code though if you would like that.. ps: i can now read the doc thanks!! erik
from monet.js.
for example:
// Generate empty actions before executing the given action.
// This can be used for simulating long delays between the start of the
// execution and the final result.
function delayAction(steps, action) {
var actions = numberRange(1, steps).map(function() { return noAction(); });
actions.push(action);
return doActions(actions);
}
kind of a "let's minimize but we can't really stop eventhough that would be fine"
from monet.js.
Related Issues (20)
- Either from exception HOT 7
- Maybe.fromEmpty? HOT 3
- Maybe.None() === Maybe.None() => false HOT 2
- Shortcut for flatMap on possibly falsy data (flatMapFromFalsy) HOT 1
- *.isInstance returns "truthy" value for every monad HOT 1
- `Either.fromPromise` HOT 6
- Rollup error - "is not exported by..." HOT 1
- Maybe.fromEmpty is not yet added to src/monet.d.ts HOT 12
- List.nth or similar HOT 3
- Applicative.apOn(value: Applicative<V>) proposal. HOT 2
- Maybe.filter should work as type guard HOT 10
- Do notation implementation
- How to supply a `Semigroup appender` to `sequenceValidation`?
- Error on "List -> find" with single value of null HOT 3
- sequenceValidation doesn't work for Fail as stated in docs
- [request for help] - casting right type on left HOT 1
- Missing type guard argument on fromFalsy
- Is it wrong to call "run()" two times in a row?
- Type 'V' does not satisfy the constraint '{}' HOT 7
- Exception is thrown if the object is without constructor
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from monet.js.