public long factMatching ( long n ) { return match ( n ) . when ( caseLong ( 0 ) ) . get ( ( ) -> 1L ) . when ( caseLong ( any ( ) ) ) . get ( i -> i * factMatching ( i - 1 ) ) . getMatch ( ) ; }
An implementation of factorial using motif pattern matching .