jaror,
@jaror@kbin.social avatar

Lenses are not always better:

fresh :: FDState s c -> (Int, FDState s c)
fresh = id &&& id
  >>> first (^. nextId)
  >>> ((i, s) -> (i, s & alive %~ Set.insert i))
  >>> second (nextId %~ (+ 1))

fresh :: FDState s c -> (Int, FDState s c)
fresh s@FDState {_nextId = i, _alive = as} =
  (i, s {_nextId = i + 1, _alive = Set.insert i as})

  • All
  • Subscribed
  • Moderated
  • Favorites
  • random
  • uselessserver093
  • Food
  • aaaaaaacccccccce
  • [email protected]
  • test
  • CafeMeta
  • testmag
  • MUD
  • RhythmGameZone
  • RSS
  • dabs
  • Socialism
  • KbinCafe
  • TheResearchGuardian
  • Ask_kbincafe
  • oklahoma
  • feritale
  • SuperSentai
  • KamenRider
  • All magazines