Questions tagged [traversable]

In Haskell, class of data structures that can be traversed from left to right, performing an action on each element. Defined in Data.Traversable.

In Haskell, class of data structures that can be traversed from left to right, performing an action on each element.

Defined in Data.Traversable.

76 questions
2
votes
4 answers

How to check if object or var is traversable in Javascript?

How can I check the object or variable is traversable in Javascript or jQuery? An object or a variable which is traversable must works in for each like object.forEach() and $.each(object, callback) in jQuery. Actually I want to validate it then use…
Milad Rahimi
  • 3,464
  • 3
  • 27
  • 39
2
votes
6 answers

How can I fold with state in Haskell?

I have a simple function (used for some problems of project Euler, in fact). It turns a list of digits into a decimal number. fromDigits :: [Int] -> Integer fromDigits [x] = toInteger x fromDigits (x:xs) = (toInteger x) * 10 ^ length xs + fromDigits…
ruben.moor
  • 1,876
  • 15
  • 27
2
votes
2 answers

Is the equivalent of Haskell's Foldable and Traversable simply a sequence in Clojure?

In Haskell we see Foldable and Traversable landing in Haskell prelude. These both do operations on sequences. Prelude Data.Sequence> map (\n -> replicate n 'a') [1,3,5] ["a","aaa","aaaaa"] Prelude Data.Sequence> fmap (\n -> replicate n 'a') (1 <|…
hawkeye
  • 34,745
  • 30
  • 150
  • 304
2
votes
1 answer

Scala prevent mixing methods

I would like to create the following trait: trait IntSet[A] extends Traversable[A] { self: Product => def foreach[U](f: A => U): Unit } case class AProduct(a: List[Int], b: List[Int]) extends IntSet[Int] { def foreach[U](f: Int => U): Unit = { …
Mikaël Mayer
  • 10,425
  • 6
  • 64
  • 101
1
vote
1 answer

Is there a name in Haskell for `[m a] -> m a`?

Let's say I have a Future monad, so Future a represents an a that may or may not yet be available. Then sequenceA automatically gives me the semantics "wait for all of these futures to be ready and give me all their values": sequenceA :: [Future a]…
jacobsa
  • 5,719
  • 1
  • 28
  • 60
1
vote
1 answer

TypeScript - using recursive generics properly

I am trying to use recursive generics in a way I can get a lot of help from editor. Here is an example: interface ServiceEndpointNode { self: string; context?: Record } const ServiceEndpoints: ServiceEndpointNode =…
1
vote
1 answer

Can trees be generalized to allow any traversable sub-tree?

Data.Tree uses a list to represent the subtree rooted at a particular node. Is it possible to have two tree types, for example one which uses a list and another which uses a vector? I want to be able to write functions which don't care how the…
loke202
  • 13
  • 2
1
vote
1 answer

How to interpret a Traversable type as an Applicative in this function?

I was experimenting with haskell classes, and I discovered that (at least some) Traversable data structures are also Applicative And when you look at the definition of Traversable, you see that it can be defined with the sequenceA…
rambi
  • 1,013
  • 1
  • 7
  • 25
1
vote
1 answer

How could sequence be written down for Arrows?

sequenceA is a well-known function: sequenceA :: (Traversable t, Applicative f) => t (f a) -> f (t a) I wonder whether we can write down something similar for Arrows. Unfortunately, I did not manage to implement the following: sequenceArr ::…
Zhiltsoff Igor
  • 1,812
  • 8
  • 24
1
vote
3 answers

How to apply a traversable of functions to a one value

What should I use if I want to have something like [a->b] -> a -> [b] basically I have a list of functions, all take in a value a and returns b. I want to apply all of them to one a and get the results [b]. Which one should I use? Thanks
1
vote
2 answers

lists:map with side-effects in Erlang

I have a list of batches(sublists) of ids and I want to iterate over this list and spawn a worker process for each id in the batch of ids. Each of these workers will query some service, get the result and send it back to the caller. In simple words…
1
vote
2 answers

Terminology of the Traversable concept

Why are we calling a flip of structure a "sequence" and why are we talking about "traverse" and "Traversal" ? I'm adding the implementation in haskell of these concepts as a matter to discussion... class (Functor t, Foldable t) => Traversable t…
Nicolas Henin
  • 3,244
  • 2
  • 21
  • 42
1
vote
1 answer

Explanation of the Return Values of the IteratorAggregate::getIterator

http://php.net/manual/en/iteratoraggregate.getiterator.php Return Values - "An instance of an object implementing Iterator or Traversable" 1) So what gets returned is always an instance of an object, correct? (I am assuming yes, but I want to make…
user9582261
1
vote
2 answers

How to write a Traversable instance for function, in Haskell?

How do I write the Traversable instance for ((->) a)? I think I could do it, if I could generically unwrap an Applicative Functor: instance Traversable ((->) k) where -- traverse :: (a -> f b) -> (k -> a) -> f (k -> b) -- traverse h t = ? -- h…
dbanas
  • 1,707
  • 14
  • 24
1
vote
0 answers

Where is the applicative in my Javascript traverse implementation?

I've tried to understand Haskell's traverse function and to implement it in Javascript, but I'm stuck. When I look at its type (Functor t, Foldable t, Applicative f) => (a -> f b) -> t a -> f (t b), I understandd that I need <$> (map in JS), <*> (ap…
user6445533