package Ġcom . r 3 . demos . ub in 2 a . plan Ċ Ċ import Ġcom . r 3 . demos . ub in 2 a . ob lig ation . O bl igation Ċ import Ġnet . cord a . core . identity . Abstract Party Ċ Ċ type alias ĠO bl ig ations Ġ= ĠList < O bl igation . State > Ċ type alias ĠO bl ig ations Map Ġ= ĠMap < Edge , ĠO bl ig ations > Ċ Ċ fun Ġget O bl ig ations Map ( ob lig ations : ĠO bl ig ations ): ĠO bl ig ations Map Ġ{ ĊĠĠĠ Ġval Ġedges Ġ= Ġoblig ations . map Ġ{ ĠPair ( Edge ( it . l ender , Ġit . borrow er ), Ġit ) Ġ} ĊĠĠĠ Ġreturn Ġedges . groupBy Ġ{ Ġit . first Ġ}. map Values Ġ{ Ġit . value . map Ġ{ Ġit . second Ġ} Ġ} Ċ } Ċ Ċ fun ĠO bl ig ations Map . ob lig ations For Edge ( l ender : ĠAbstract Party , Ġborrow er : ĠAbstract Party ): ĠO bl ig ations Ġ{ ĊĠĠĠ Ġreturn Ġthis [ Edge ( l ender , Ġborrow er )]. or Empty () Ċ } Ċ Ċ fun ĠO bl ig ations Map . all Entries (): ĠList < O bl igation . State > Ġ{ ĊĠĠĠ Ġreturn Ġthis . values . flatMap Ġ{ Ġit Ġ} Ċ } Ċ Ċ data Ġclass ĠO bl ig ations Graph ( val Ġgraph : ĠGraph , Ġval Ġoblig ations : ĠO bl ig ations Map , Ġval Ġcycles : ĠSet < Set < Cycle >>) Ċ Ċ fun Ġoblig ations Graph From ( listOf O bl ig ations : ĠO bl ig ations , Ġuse Extended Components : ĠBoolean Ġ= Ġfalse ): ĠO bl ig ations Graph Ġ{ ĊĠĠĠ Ġval Ġgraph Ġ= Ġdirected Graph Of ( listOf O bl ig ations ) ĊĠĠĠ Ġval Ġoblig ations Ġ= Ġget O bl ig ations Map ( listOf O bl ig ations ) ĊĠĠĠ Ġval Ġcycles Ġ= Ġif Ġ( use Extended Components ) Ġ Ġfind Extended Component Cycles ( graph ) Ġelse Ġfind Cycles In Graph ( graph ) ĊĠĠĠ Ġreturn ĠO bl ig ations Graph ( graph , Ġoblig ations , Ġcycles ) Ċ } Ċ