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
1
vote
2 answers

Lifting function `a → b → c` to `[a] → [b] → [[c]]`

I would like to have a function foo :: (a → b → c) → [a] → [b] → [[c]] that takes a function f :: a → b → c and two lists xs and ys and returns a grid (i.e. a list of lists) containing the values of f applied to every combination of values from xs…
Manuel Eberl
  • 7,858
  • 15
  • 24
1
vote
2 answers

Why does not sequence work with List of Validations

I think I understand what sequence is. I am wondering why it does not work with List[ValidationNel]. For instance: The sequence works fine with List[Option]] scala> val os = List(1.some, 2.some) os: List[Option[Int]] = List(Some(1), Some(2)) scala>…
Michael
  • 41,026
  • 70
  • 193
  • 341
1
vote
1 answer

Get indices of Applicative Traversable without dummy

Let's say I have some v, which is both Applicative and also Traversable. How can I get a v with the indices of v? For a concrete example, consider V3 from Linear. I want V3 0 1 2. One way is to use mapAccumL with a dummy, for example: snd $…
yong
  • 3,583
  • 16
  • 32
0
votes
1 answer

Implement Scala Cats Traverse for State

I've been writing my own version of Scala Cats (to assist others when learning this library). I've implemented my own versions of most type classes, but am stuck with a custom implementation of Traverse for State. The function to implement is: def…
D Ainslie
  • 33
  • 1
  • 6
0
votes
1 answer

List Traversal in a lazy setting that produces expressions in WHNF

I simulate lazy evaluation, i.e. evaluate only when needed and only once, in JS with Proxy and run into a problem with Traversable (mapA instead of traverse at the term level): const r = List.mapA({map: Opt.map, ap: Opt.ap, of: Opt.of}) (x => (x &…
user5536315
0
votes
1 answer

Haskell traverse and filter through a list while lifting results

Say I have code where I want to do the following: Input: a list of strings [String] Operation (checkSat and checkResult) Obtains a boolean from an input string. Output: If everything in the input is parseable into a boolean, only return those…
gust
  • 878
  • 9
  • 23
0
votes
1 answer

What is This More General Almost-Traversal Operation

Trying to wrap my mind around traversals - or maybe something slightly different, in this case. I understand a traversal to be an operation that performs an applicative operation (or effect) over a traversable structure. So for example from…
0
votes
1 answer

TraversableOnce MonadOps in Scala collection library

I'm looking at Scala 2.12 Collection Library sources and noticed the following thing: trait TraversableOnce[+A] extends Any with GenTraversableOnce[A] { //methods implicit class MonadOps[+A](trav: TraversableOnce[A]) { def map[B](f: A =>…
St.Antario
  • 26,175
  • 41
  • 130
  • 318
0
votes
1 answer

How to return instance of Traversable to meet following assertion code?

Here I have a challenging php function that should return an instanceof Traversable (iterator) and also need to meet other assertions that test this function. Function has no errors, it computes Fibonacci numbers. The function can be modified, it is…
Till May
  • 3
  • 3
0
votes
0 answers

How to access a property that is of type array in a many to many relationship with an intermediate table

here is the error that symfony4 returns : Could not determine access type for property "artist" in class "App\Entity\Event": The property "artist" in class "App\Entity\Event" can be defined with the methods "addArtist()", "removeArtist()" but the…
Sandrine
  • 1
  • 1
0
votes
1 answer

Why is scala.collection.immutable.List[Object] not GenTraversableOnce[?]

Simple question, and sorry if this is a stupid question as I am just beginning in scala. I am getting a type mismatch error that says: found : (AnyRef, org.apache.tinkerpop.gremlin.hadoop.structure.io.VertexWritable) => List[Object] required:…
Paul
  • 1,106
  • 1
  • 16
  • 39
0
votes
1 answer

What is a "applicative transformation" in naturality of traversability?

The traverse and sequenceA function in Traversable class must satisfy the following 'naturality' laws: t . traverse f == traverse (t . f) t . sequenceA == sequenceA . fmap t for every 'applicative transformation' t. But what is it? It doesn't seem…
Dannyu NDos
  • 2,458
  • 13
  • 32
0
votes
1 answer

What does it mean When implementing interface use IteratorAggregate or Iterator in its name in php?

I am new to php and learning it from php.net. As we know when we want to implement Traversable interface we implements IteratorAggregate or Iterator interface with user defined classes that implements the Traversable interface internally. But one…
user8693138
0
votes
1 answer

filtered list cartesian product without intermediate list

I am trying to create a filtered cartesian product from a given list of lists. The naive solution is the following: import Data.Traversable (sequence) predicate :: [T] -> Bool predicate = ... filteredCartesianProduct :: [[T]] ->…
lanskey
  • 457
  • 3
  • 13
-1
votes
1 answer

"string" Implementation in Text.Parser.Char

First, just some quick context. I'm going through the Haskell Programming From First Principles book, and ran into the following exercise. Try writing a Parser that does what string does, but using char. I couldn't figure it out, so I checked out…
arcticmatt
  • 1,956
  • 1
  • 19
  • 36