Skip to content

ornamental/compiletime-topological-sort

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Compile-Time Topological Sorting

This repository presents a solution to compile-time dependency injection problem over pure functions.

Given a set of functions
{Fi: (Pi,1, .., Pi,Ni) => Ri | i ∈ 1..N},
the functions are sorted in such way σ that each type from the set
{Pσ(i),1, .., Pσ(i),Nσ(i)}
is uniquely covered by a type from the set of return types
{Rσ(k) | k ∈ 1..i-1}.

If such an ordering exists, the functions of these types may be combined into a single function
S: () => (R1, .., RN).
The present implementation combines given functions to an equivalent function with shapeless' heterogeneous list as return type
() => Rσ(N) :: Rσ(N-1) :: .. :: Rσ(1) :: HNil
and allows to retrieve the desired subset of the computed values, ordered arbitrarily.

Example. See TopologicalSortTest.scala.

About

Implementation of topological sort at compile time

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages