<commit_before>{-# LANGUAGE LambdaCase   #-}

module Ling.Session.Core
  ( array
  , loli
  , oneS
  , fwds
  , fwd
  , endS
  , endRS
  , endedS
  , endedRS
  , logOp
  , dualOp
  , dualized
  , termS
  , Dual(..)
  ) where

import           Ling.Norm
import           Ling.Prelude
import qualified Ling.Raw     as Raw
import           Prelude      hiding (log)

array :: TraverseKind -> Sessions -> Session
array = Array

oneS :: Session -> RSession
oneS s = Repl s ø

loli :: Op2 Session
loli s t = Array ParK . Sessions $ oneS <$> [dual s, t]

fwds :: Dual session => Int -> session -> [session]
fwds n s
  | n <  0    = error "fwd: Negative number of channels to forward"
  | n == 0    = []
  | n == 1    = [s]
  | otherwise = s : dual s : replicate (n - 2) (log s)

fwd :: Int -> Endom Session
fwd n s = Array ParK . Sessions $ oneS <$> fwds n s

-- Here one can tune what we consider ended.
-- Being ended implies:
-- * No need to actually use the channel
-- * Forwarders thus never use them
-- For instance these could be ended.
-- * `Array _ []` (thus `{}` and `[]`)
-- * `Array _ [ended ,..., ended]`<commit_msg>Refactor (make Session.Core.array more convenient)<commit_after>{-# LANGUAGE LambdaCase   #-}

module Ling.Session.Core
  ( array
  , loli
  , oneS
  , fwds
  , fwd
  , endS
  , endRS
  , endedS
  , endedRS
  , logOp
  , dualOp
  , dualized
  , termS
  , Dual(..)
  ) where

import           Ling.Norm
import           Ling.Prelude
import qualified Ling.Raw     as Raw
import           Prelude      hiding (log)

array :: TraverseKind -> [RSession] -> Session
array k = Array k . Sessions

oneS :: Session -> RSession
oneS s = Repl s ø

loli :: Op2 Session
loli s t = Array ParK . Sessions $ oneS <$> [dual s, t]

fwds :: Dual session => Int -> session -> [session]
fwds n s
  | n <  0    = error "fwd: Negative number of channels to forward"
  | n == 0    = []
  | n == 1    = [s]
  | otherwise = s : dual s : replicate (n - 2) (log s)

fwd :: Int -> Endom Session
fwd n s = Array ParK . Sessions $ oneS <$> fwds n s

-- Here one can tune what we consider ended.
-- Being ended implies:
-- * No need to actually use the channel
-- * Forwarders thus never use them
-- For instance these could be ended.
-- * `Array _ []` (thus `{}` and `[]`)
-- * `Array _ [ended ,..., ended]`
{'fraction_non_alphanumeric': 0.13272410791993036, 'fraction_numerical': 0.004351610095735422, 'mean_word_length': 2.274928774928775, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1735854', 'n_tokens_mistral': 841, 'n_tokens_neox': 809, 'n_words': 290}