275 questions
3
votes
1
answer
54
views
Build Prism path selectively base on values
Here is the data structure
data Fruit = Apple String Int
| Banana String
| ....
| Orange Int Int
data Baseket = BaseketA Fruit
| BaseketB Fruit Int
...
3
votes
0
answers
133
views
how to use the choosing and chosen lenses? [duplicate]
Consider these datatypes:
data SomeNestedData = SomeNestedData { sndValue :: Int }
data OtherNestedData = OtherNestedData { ondValue :: Int }
data Foo = Bar SomeNestedData | Baz OtherNestedData
How ...
1
vote
0
answers
232
views
Setup a Zustand readonly store
We are using for our frontend application store Zunstand with Immer for immutability and Zustand lens for separating slices.
I noticed that, due to an error runtime in Javascript console, we used a ...
1
vote
1
answer
122
views
How to delete an element from an array using lenses
I'm trying to remove an element from an Array a using the index of the element but I can't find a way to do it with Lenses. I'm also wondering why Array does not provide an instance for the At lens. ...
3
votes
2
answers
267
views
Using lenses to view a Map as key-value pairs?
The traverse lens (is it a lens?) allows looking at Map key value in a value-by-value basis. For example:
import Data.Map
import Control.Lens
simpleMap :: Map Int Char
simpleMap = fromList [(1, 'a'), ...
9
votes
1
answer
122
views
Is there a van Laarhoven optic based on the Monad typeclass?
As I understand it, each van Laarhoven optic type can be defined by a constraint on a type constructor:
type Lens s t a b = forall f. Functor f => (a -> f b) -> s -> f t
type ...
0
votes
1
answer
78
views
How to construct a lens of 2 properties?
Suppose I have a record like this:
type Order = | Order
type OrderBook =
{
PrimaryOrderID : Guid
Orders : Map<Guid, Order>
}
I would like to do nested updates using lenses.
Here ...
1
vote
2
answers
218
views
How to use FSharpPlus.Lens to specify the index of a list?
The sample code of the documentation defines _pageNumber using List._item, but I can't seem to find an example of its use.
I tried the following code but it gave an error.
view (Book._pageNumber 1) ...
2
votes
2
answers
167
views
What is a `Prism' s a` but with a context `ctx`?
A type Prism' s a = Prism s s a a (hackage) can be thought of as a relation between some structure s and its member a, such that you can always produce the structure from the member (a -> s), but ...
1
vote
0
answers
192
views
dynamic Optional.fromPath
Can i access nested properties with monocle-ts in a dynamic fashion?
The closest i can find directly from the library is the Optional.fromPath, combined with a dynamic path. Based on the example from ...
1
vote
1
answer
119
views
How to compare lenses in Haskell
I am curious about Eq instance for lenses.
Lenses are functions. It is hard to compare arbitrary functions, but lenses are special class of functions.
I am thinking about using QuickCheck Arbitrary ...
3
votes
2
answers
208
views
What is the difference between single double qoute/apostrophe in template-haskell?
When learning about Haskell lenses with the Optics package, i encountered the following example:
data Person = Person
{ _name :: String
, _age :: Int
}
makeLenses ''Person
makePrisms 'Person
...
3
votes
2
answers
240
views
What is the appropriate abstraction for a lens which can fail as a setter?
I would like to define something like a lens, but which can fail when trying to set. See fooLens in the following example.
{-# LANGUAGE RankNTypes #-}
import Data.Char (toUpper)
import Data.Functor....
1
vote
2
answers
131
views
Eliminating `flip` in Haskell lens
I'm trying to get the hang of lenses. Is there a more idiomatic way to write the following? (placeholders preceded by underscores)
flip (set _lens) _a . fmap _f
To me, the use of flip seems to ...
1
vote
0
answers
113
views
Functional "upsert" on nested array in nested array of objects: use optics somehow?
Suppose I have the following types
interface State {
parents: Parent[]
}
interface Parent {
uniqueName: string
children: Child[]
// other props
}
interface Child {
uniqueName: string
...
1
vote
1
answer
151
views
Traversal to combine multiple map operations into single ADT
Given a record consisting of multiple maps, how can I write a traversal (or prism, or Lens' TestLens (Maybe Interim)) that allows me to group together lookups?
First off, my current attempts.
data ...
2
votes
1
answer
138
views
Is there an appropriate optic for set membership?
I’m using Data.Sets in deeply-nested heterogeneous data structures, and thought it would be helpful to create a Prism for set membership. Hence:
membership :: (Ord a) => a -> Prism' (Set a) (Set ...
0
votes
0
answers
157
views
How to generalize from Lens to Traversal and from Getter to Fold optic?
I achieved to implement Getter, Setter, Lens, LensAt (aka At in monocle) and LensOpt (aka Optional in monocle), However, I failed to generalize from Lens to Traversal and from Getter to Fold by adding ...
3
votes
1
answer
662
views
Functional Programming/Optic concept that takes a partial object and returns a "filled in" object using lenses and traversals?
(Edit I'm using monocle-ts, but if it's not possible with monocle-ts (since the author even says it's just a partial port of the original Monocle for Scala) but if there is something in another optics ...
4
votes
1
answer
434
views
Updating a nested data structure using lenses
I'm currently trying to make parts of my code more concise using lenses. In particular, I have a HTTP Request where I want to replace the value of a header with the name Private-Header.
I managed to ...
8
votes
0
answers
126
views
Is there a Lens/Optic that can use to dig deeply into multidimensional maps?
I've had a bit of difficulty using Lenses with Maps. I have maps that look like this Map String (Map String Int). These are multidimensional arrays, and I usually set them up with known dimensions. I ...
0
votes
1
answer
778
views
unable to insert or upsert data from kafka topic to kudu table using lenses kudu sink connector
lenses kudu sink connector version = kafka-connect-kudu-1.2.3-2.1.0
kudu table schema
CREATE TABLE IF NOT EXISTS table_name(
su_id bigint not null,
su_tenant_id int null,
su_bu_id int null,
...
1
vote
1
answer
156
views
lifo queues as optics
Consider a list of items [a] and a pair of functions
pop :: [a] -> (Maybe a, [a])
pop = headMay &&& tailSafe
push :: a -> [a] -> [a]
push = (:)
which just provide the list with ...
0
votes
1
answer
106
views
Extend one Traversal lens with another Traversal lens
Let's say I have a Node and it can have children and siblings and I have traversal lens implementations for them. How do I compose them into a single lens that traverses both children and siblings?
...
1
vote
1
answer
74
views
issues reproducing Haskell lens tutorial
I feel like I am doing something wrong, as I am not even managing to reproduce Haskell's lens tutorial:
> import Control.Lens
> data Point = Point { _x :: Double, _y :: Double } deriving (Show)
...