Why is the class/constructor required as a parameter for `traverse` (or sequence)?
See original GitHub issueA Fantasy-land
compliant version of traverse
might go something like this:
S.traverse (Array) (S.words) (S.Just ('foo bar baz'))
But why are we asking for the first (Array)
parameter? If the words function must return an Array, could we not access the constructor of the Array as such:
const foo = [1,2,3]
const foo2 = foo.constructor.of( 4,5,6 )
So why do we need Array
at all? Here S.words
returns an Array
Monad contained within the Maybe
. We can then derive the Array
constructor as mentioned above to sequence
an Array
of Maybe
s.
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Constructors in Java - GeeksforGeeks
A constructor that has parameters is known as parameterized constructor. If we want to initialize fields of the class with our own values,...
Read more >control initialize order when Python dataclass inheriting a class
There are two reasons for calling a parent's constructor, 1) to instantiate arguments that are to be handled by the parent's constructor, ...
Read more >Untitled
C.3 — A parameter is a value that is passed into a constructor. These are often referred to as actual parameters. Introduction to...
Read more >Abstract Data Types in C++
An array of class-type objects is default initialized by calling the default constructor on each element. Thus, the element type must have an...
Read more >Traverse - Typelevel
In order to call traverse Id needs to be Applicative which is straightforward - note that while Id just wraps an A ,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Pardon the silly pattern, but this is one way that I have implemented traverse on a
Maybe
type: https://github.com/evilsoft/crocks/blob/master/src/core/Maybe.js#L210The left side of that
either
function is for theNothing
case, so it composes aNothing
constructor before theaf
orApplicative
function resulting in theApplicative m => m Maybe a
So in short: the traverse is “run”, but the “lifing” function is not. That
af
needs to come from somewhere, and that is what theTypeRep
ora -> m a
in the case ofcrocks
(we accept both theApplicative
TypeRep
or anApply
returning function, which is why this pattern looks so silly.)EDIT: notice that
af
is based on thef
that is passed in and it only appears in the left orNothing
case.EDIT AGAIN: Oh looks like the comment I was replying to was deleted. So sorry about that!
Ah, right ok, you get
Nothing
not[ Nothing ]