Skip to content

Instantly share code, notes, and snippets.

@mithrandi
Created January 13, 2015 14:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mithrandi/2490e7394b264d337b25 to your computer and use it in GitHub Desktop.
Save mithrandi/2490e7394b264d337b25 to your computer and use it in GitHub Desktop.
Lenses example with IO
findDataset :: Dataset -> Maybe String
findDataset (view datasetName -> Just name) = M.lookup name datasets
findDataset (view datasetName -> Nothing) = Nothing
update_dataset_id :: Dataset -> IO Dataset
update_dataset_id d =
case findDataset d of
Just did -> return $ d & datasetId ?~ did
Nothing -> (\did -> d & datasetId ?~ did) <$> toString <$> nextRandom
update_all_dataset_ids :: Deployment -> IO Deployment
update_all_dataset_ids = mapMOf (nodes.traversed.applications.traversed.volume.dataset) update_dataset_id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment